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

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

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值