现在的位置: 首页 > 综合 > 正文

某大学生的作业(1)–题目

2013年01月10日 ⁄ 综合 ⁄ 共 2494字 ⁄ 字号 评论关闭

information on the connectivity of nodes and networks. Nodes may be connected
to varying numbers of networks and networks may be connected to varying
numbers of nodes. You may assume a maximum of 20 networks and 20 nodes at
one time will need to be represented.
Read the supplied file of connect statements (input.txt) of the form:
connect(node, network)
populating your data structure as you read down the file.
Your data structure should be designed for efficient retrieval of connection
information. Numerous design choices are available but do not store the data as a
simple copy of the input file. Try to build a model of the network structure rather
than directly of the input file. For example, try to use Node and Network classes
as part of your solution.
Devise an interactive facility to query the stored topology, offering the user the
following menu of choices:
Which search do you require?
1. networks – list all networks connected to a particular node
2. nodes – list all the nodes connected to a particular network
3. quit.
Selecting item 1 or 2, should cause the user to be prompted to input a node name
or network name, respectively, to be used as the basis for the search. Continue the
user dialogue, enabling the user to undertake further searches, until the quit option
is selected. Just use simple console io for user interactions.

input.txt内容如下
connect(piquard, ethernet)
connect(piquard, firewire)
connect(worf, ethernet)
connect(worf, bluetooth)
connect(riker, ethernet)
connect(riker, wi-fi)
connect(crusher, firewire)
connect(laforge, ethernet)
connect(laforge, firewire)
connect(data, ethernet)
connect(data, wi-fi)
connect(guinan, wi-fi)
connect(o'brien, ethernet)
connect(o'brien, bluetooth)
connect(troy, wi-fi)
connect(troy, firewire)

main函数也给了一部分
import java.io.*;
import java.util.*;

/**
* Exercise 29
*
*/
class Main {

public static void main(String args[]) throws IOException {

// read input file and build data structure in model

FileReader reader = new FileReader("input.txt");
BufferedReader bReader = new BufferedReader(reader);

String line = bReader.readLine();

while (line != null) { // check for eof
try {
StringTokenizer parseString = new StringTokenizer(line);

String delimiters = " (),/t/n";

String connectKeyword = parseString.nextToken(delimiters);
String nodeName = parseString.nextToken(delimiters);
String netName = parseString.nextToken(delimiters);

// expand here to build data structure .............
}

catch (NoSuchElementException e) {
System.out.println("Invalid input line: " + line
+ ". Skipping ....");
}

line = bReader.readLine();
}

// allow user to query data structure
options();
}

/**
* Prompt users with options to either search for node,
* or network, or to quit
*/
public static void options() {

Scanner keyboard = new Scanner(System.in);

// expand here .............

} // end options
} // end class

本人不是很懂,不懂的人就别乱回了,谢谢
运行满足要求给分
(注意要求中要有结构问题,自己构建结构)

 

 

抱歉!评论已关闭.