Project
Project # 3/data (3).zip
friends6x6.csv
David,Frank Cindy,Becky,Emily Aaron Becky,Cindy,Frank,Emily Frank,David,Becky,Emily Emily,Cindy,Becky,Frank
friends6x12.csv
David,Cindy,Becky,Frank,Emily Cindy,David,Becky,Emily Aaron,Becky,Frank,Emily Becky,David,Cindy,Aaron,Frank,Emily Frank,David,Aaron,Becky,Emily Emily,David,Cindy,Aaron,Becky,Frank
friends26x26.csv
Aaron,Violet Liam,Walter,Xander,Rolf,Hillary Emily,Parker,Yuli Gillian,Nina,Josh Quinn,Marylyn Terah,David Simone,Marylyn,Rolf,Hillary Irene,Parker,Yuli Yuli,Xander,Violet,Emily,Irene David,Terah Cindy,Xander Walter,Liam Becky,Frank,Rolf Xander,Cindy,Liam,Josh,Hillary,Yuli Frank,Becky,Owen Nina,Gillian Josh,Xander,Gillian Owen,Frank Parker,Emily,Irene Ursula Kyle Violet,Aaron,Yuli Marylyn,Rolf,Simone,Quinn Rolf,Becky,Liam,Marylyn,Simone Hillary,Xander,Liam,Simone,Zera Zera,Hillary
friends26x52.csv
Aaron,David,Violet,Parker Liam,Walter,Xander,Rolf,Hillary,Irene,Owen,Gillian Emily,Violet,Hillary,Parker,Quinn,Zera,Yuli Gillian,Liam,Nina,Josh,Zera Quinn,Kyle,Marylyn,Emily,Hillary,Owen Terah,David,Yuli Simone,David,Marylyn,Nina,Rolf,Hillary Irene,Liam,Marylyn,Frank,Rolf,Parker,Yuli Yuli,Terah,Xander,Violet,Emily,Irene,Zera David,Aaron,Terah,Simone Cindy,Xander Walter,Liam,Rolf Becky,Frank,Rolf Xander,Cindy,Liam,Josh,Hillary,Yuli Frank,Kyle,Becky,Irene,Owen Nina,Simone,Gillian Josh,Xander,Marylyn,Gillian Owen,Liam,Frank,Quinn Parker,Aaron,Emily,Irene Ursula,Marylyn,Zera Kyle,Frank,Quinn Violet,Aaron,Emily,Yuli Marylyn,Ursula,Rolf,Simone,Josh,Irene,Quinn Rolf,Walter,Becky,Liam,Marylyn,Simone,Hillary,Irene Hillary,Xander,Liam,Emily,Rolf,Simone,Quinn,Zera Zera,Ursula,Emily,Hillary,Gillian,Yuli
Friendship.java
Friendship.java
package
edu
.
cwu
.
cs
.
cs302
.
friendnetwork
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
List
;
import
java
.
util
.
Queue
;
import
java
.
util
.
Random
;
public
class
Friendship
{
public
static
void
main
(
String
[]
args
)
{
IFriendshipGraph
network
=
new
FriendshipGraph
();
network
.
create
(
"friends26x100.csv"
);
System
.
out
.
println
(
network
);
List
<
String
>
names
=
new
ArrayList
<
String
>
(
network
.
getPeople
());
Random
r
=
new
Random
(
302
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
String
from
=
names
.
get
(
r
.
nextInt
(
names
.
size
()));
String
to
=
names
.
get
(
r
.
nextInt
(
names
.
size
()));
Queue
<
String
>
relationship
=
network
.
getRelationship
(
from
,
to
);
System
.
out
.
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.java
IFriendshipGraph.java
package
edu
.
cwu
.
cs
.
cs302
.
friendnetwork
;
import
java
.
util
.
List
;
import
java
.
util
.
Queue
;
public
interface
IFriendshipGraph
{
/**
* Returns the names of all the people in the friendship graph
*
@return
a list of names
*/
public
List
<
String
>
getPeople
();
/**
* 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
*/
public
Queue
<
String
>
getRelationship
(
String
person1
,
String
person2
);
/**
* Create the friendship graph from a CSV file
*
@param
filename The name of the CSV file
*/
public
void
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
public
String
toString
();
/**
* Indicates if everyone is friends either directly or indirectly
*
@return
true if everyone is friends in some way
*/
public
boolean
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
*/
public
IFriendshipGraph
minimalGraph
();
public
boolean
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
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.