4. .println(from +" -- > "+ to +": "+" "+ relationship);
}
System.out.println();
if(network.allFriends()){
System.out.println("Everyone is friends!");
}else{
System.out.println("Some people have no friends.");
}
System.out.println();
System.out.println("Minimal Friendship Network");
System.out.println("--------------------------");
IFriendshipGraph graph = network.minimalGraph();
if(graph.isEmpty())
System.out.println("Cannot create a minimal graph.");
else
System.out.println(network.minimalGraph());
}
}
IFriendshipGraph.javaIFriendshipGraph.javapackage edu.cwu.cs
.cs302.friendnetwork;
import java.util.List;
import java.util.Queue;
publicinterfaceIFriendshipGraph{
/**
* Returns the names of all the people in the friendship graph
* @return a list of names
*/
publicList<String> getPeople();
5. /**
* Returns a list showing the connection between two people,
if one exists.
* @param person1 The name of the first person
* @param person2 The name of the second person
* @return An ordered list
*/
publicQueue<String> getRelationship(String person1,String per
son2);
/**
* Create the friendship graph from a CSV file
* @param filename The name of the CSV file
*/
publicvoid create(String filename);
/**
* Returns a multi-
line string containing the friendship information. For example:
*
* Aaron:
* Becky: Cindy Frank Emily
* Cindy: Becky Emily
* David: Frank
* Emily: Cindy Becky Frank
* Frank: David Becky Emily
*
* @return A string
*/
@Override
publicString toString();
/**
* Indicates if everyone is friends either directly or indirectly
* @return true if everyone is friends in some way
*/
6. publicboolean allFriends();
/**
* Create a minimal friendship graph. If some people are not
friends, either directly or indirectly, then return an empty graph.
* @return the minimal friendship graph
*/
publicIFriendshipGraph minimalGraph();
publicboolean isEmpty();
}
Project # 3/Friendship Network Project Details.docx
Friendship Network Project Details
In this project, you will create an application that determines
how two people are related via friends. The application reads in
a CSV file containing friendship information. The program will
then create a graph representing the friendship relationships and
use that graph to determine how two random people are related,
such as friend-of-a-friend-of-friend.
Example
Here is an example of the output from the program showing the
friendship information and the relationship information:
Aaron: Becky: Cindy Frank Emily Cindy: Becky Emily David:
Frank Emily: Cindy Becky Frank Frank: David Becky Emily
Cindy -- > Aaron: []David -- > David: [David]Emily -- > Aaron:
[]Cindy -- > Frank: [Cindy, Becky, Frank]Emily -- > Frank:
[Emily, Frank]Aaron -- > Aaron: [Aaron]Emily -- > Cindy:
[Emily, Cindy]Emily -- > David: [Emily, Frank, David]Becky --
> Aaron: []Cindy -- > David: [Cindy, Becky, Frank, David]
You can see that Cindy is a friend to David via Becky and
Frank, and David is a friend to himself, and that there is no way
that Becky and Aaron have no relationship.
Project Design
7. For this project, you are given a driver program
(Friendship.java) and an interface (IFriendshipGraph.java). You
are to create a class (FriendshipGraph.java) that implements the
interface.
There are three different levels for the program:
1. A class that provides an implementation
of getRelationship(a,b) which tells how two people are related
to each other through their friends using code from the
textbook. The methods allFriends() and minimalGraph() return
false and an empty graph, respectively. (Grade "C"-range)
2. A class that provides an implementation
of getRelationship(a,b) which tells how two people are related
to each other through their friends using code from the
textbook andimplements the
methods allFriends() and minimalGraph() using code from the
textbook. (Grade "B"-range)
3. The network code from the textbook is overkill for this
project as the code is designed for a digraph with weighted
edges, and the friendship graph is an undirected graph where all
edge weights are 1. The graph representation can be simplified.
One possible simplification is to represent the graph as a Map
of names and the set of the person's friends. Simplify the
textbook code and indicate in the Javadoc comments how you
simplified the textbook code. (Grade "A"-range)
Data
The data file contains the Java files and friendship CSV files.
data.zip