My homework was to design and implement a simple social network program in Java. I should use an adjacency matrix data structure in my implementation. Write a social network program in Java. The default information for this network is stored in two files: index.txt and friend.txt. The file index.txt stores the names of the people in the network – you may assume that we only store the given names and these names are unique; and friend.txt stores who knows whom. The program must read these two files. The following section describes the format of these two files. The friend.txt takes the following format. The first line is the number of pairs of friends. Each subsequent line has two integer numbers. The first two numbers are the indices of the names. The following is an example of friend.txt: 5 0 3 1 3 0 1 2 4 1 5 The index.txt stores the names of the people in the network. The first line is the number of people in the file; for example: 6 0 Gromit 1 Gwendolyn 2 Le-Spiderman 3 Wallace 4 Batman 5 Superman The second line “Gromit” is the label for vertex 0, the third line "Gwendolyn" is for vertex 1. For this system, we will only record the given names (without spaces). By looking at the content of these two files, we know that Gromit is a friend of Wallace and Wallace is a friend of Gromit. We also know that Gwendolyn knows Wallace and Wallace knows Gwendolyn, and so on. Unknown to Wallace and Gromit, Gwendolyn is a friend of Superman! To build the social network, the program reads both files. It uses friend.txt to build the vertices and edges of the social network, and use index.txt to label the vertices. If it fails to read the files (such as file not found), then it must also print appropriate error messages using System.err. The program must also check that the number of relations or indices read is the same as the number of relations or indices specified at the start of each file. The two files above are kept short to simplify the explanation and can be used when you first start developing the program. Eventually, the program will be tested with larger datasets of about 20 friends and 30 pairs of friends.
My homework was to design and implement a simple social network program in Java. I should use an adjacency matrix data structure in my implementation.
Write a social network program in Java. The default information for this network is stored in two files: index.txt and friend.txt. The file index.txt stores the names of the people in the network – you may assume that we only store the given names and these names are unique; and friend.txt stores who knows whom. The program must read these two files. The following section describes the format of these two files.
The friend.txt takes the following format. The first line is the number of pairs of friends. Each subsequent line has two integer numbers. The first two numbers are the indices of the names. The following is an example of friend.txt:
5
0 3
1 3
0 1
2 4
1 5
The index.txt stores the names of the people in the network. The first line is the number of people in the file; for example:
6
0 Gromit
1 Gwendolyn
2 Le-Spiderman
3 Wallace
4 Batman
5 Superman
The second line “Gromit” is the label for vertex 0, the third line "Gwendolyn" is for vertex 1. For this system, we will only record the given names (without spaces). By looking at the content of these two files, we know that Gromit is a friend of Wallace and Wallace is a friend of Gromit. We also know that Gwendolyn knows Wallace and Wallace knows Gwendolyn, and so on. Unknown to Wallace and Gromit, Gwendolyn is a friend of Superman!
To build the social network, the program reads both files. It uses friend.txt to build the vertices and edges of the social network, and use index.txt to label the vertices. If it fails to read the files (such as file not found), then it must also print appropriate error messages using System.err.
The program must also check that the number of relations or indices read is the same as the number of relations or indices specified at the start of each file. The two files above are kept short to simplify the explanation and can be used when you first start developing the program. Eventually, the program will be tested with larger datasets of about 20 friends and 30 pairs of friends.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps