Complete a new class for this scenario called SocialNetwork
Create a class called SocialNetwork. This class should be based on the class DiGraph.
You can either:
• Have a field in the class SocialNetwork that is an object DiGraph (better)
• Make SocialNetwork a subclass of DiGraph with additional methods given below (best)
The constructor for this class should have no parameters, and it should create and initialise an 
adjacency-list-based directed graph that represents the SocialNetwork network as shown in the 
diagram.
For example:
SocialNetwork theSocialNetwork = new SocialNetwork();
should create the graph as shown in the diagram above.
[Up to 10 marks for use of inheritance]
2. Write the method:
public ArrayList<String> broadcastsTo(String person)
This method takes the name of a person and should return an ArrayList of String objects, which 
contains the names all the followers of person.
For example:
theSocialNetwork.broadcastsTo(Names.networkMembers[DANA]);
should return an ArrayList that contains [Bina, Cato, Fern, Geno] and nothing else.
Check the edges to resolve this method
[10 marks]
3. Refactor the depth first search method in the class Traversal
Current method header:
public static void DFS(ArrayList<Integer>[] adjList, Integer startNode)
Refactored method header:
public static boolean DFS(ArrayList<Integer>[] adjList, 
Integer startNode, Integer destinationNode)
The refactored method will return true if the destinationNode is encountered in the subgraph 
descending from startNode.
[5 marks]
4. Write the method:
public boolean canReach(String source, String target)
This method takes the name of a person starting a broadcasting a story (source) and the name of 
the person that the story is broadcast to (target). 
It uses the refactored depth first search to see if the story will get from the source to the target and 
should return true if the story will get from the source to the target, and false if there is no path from 
the source to the target.
[5 marks]
5. Refactor the breadth first search method in the class Traversal
Current method header:
public static void BFS(ArrayList<Integer>[] adjList, Integer startNode)
Refactored method header:
public static ArrayList<String> BFS(ArrayList<Integer>[] adjList, 
Integer startNode) 
The refactored method will return an ArrayList of all of the names of the visited nodes in the graph 
structure descending from startNode.
[5 marks]
6. Write the method:
public ArrayList<String> receiversOf(String person)
This method takes the name of a person who has started a story and uses a breadth first search to 
return an ArrayList of String objects that contains the names of all the person who will receive the 
story broadcast by that person.
For example:
theSocialNetwork.receiversOf(Names.networkMembers[ABEL]);
should return an ArrayList that contains 
[Bina, Cato, Dana, Eden, Fern, Geno, Hedy, Inez, Jodi]
and nothing else.
[5 marks]
Correct Output for each test
--------------------------------------------------------------------------------
broadcastTo test
Followers of Abel: [Cato]
Followers of Bina: [Abel]
Followers of Cato: [Abel]
Followers of Dana: [Bina, Cato, Fern, Geno]
Followers of Eden: [Cato, Dana, Fern, Jodi]
Followers of Fern: [Dana]
Followers of Geno: [Fern, Inez]
Followers of Hedy: [Fern, Jodi]
Followers of Inez: [Geno]
Followers of Jodi: [Inez]
--------------------------------------------------------------------------------
canReach test
Abel can reach Bina Cato Dana Eden Fern Geno Hedy Inez Jodi 
Bina can reach Dana Eden Fern Geno Hedy Inez Jodi 
Cato can reach Abel Bina Dana Eden Fern Geno Hedy Inez Jodi 
Dana can reach Eden Fern Geno Hedy Inez Jodi 
Eden can reach no one!
Fern can reach Dana Eden Geno Hedy Inez Jodi 
Geno can reach Dana Eden Fern Hedy Inez Jodi 
Hedy can reach no one!
Inez can reach Dana Eden Fern Geno Hedy Jodi 
Jodi can reach Eden Hedy 
--------------------------------------------------------------------------------
receiversOf test
Receivers of Abel: [Bina, Cato, Dana, Eden, Fern, Geno, Hedy, Inez, Jodi]
Receivers of Bina: [Dana, Fern, Eden, Geno, Hedy, Inez, Jodi]
Receivers of Cato: [Abel, Dana, Eden, Bina, Fern, Geno, Hedy, Inez, Jodi]
Receivers of Dana: [Fern, Eden, Geno, Hedy, Inez, Jodi]
Receivers of Eden: []
Receivers of Fern: [Dana, Eden, Geno, Hedy, Inez, Jodi]
Receivers of Geno: [Dana, Inez, Fern, Eden, Jodi, Hedy]
Receivers of Hedy: []
Receivers of Inez: [Geno, Jodi, Dana, Eden, Hedy, Fern]
Receivers of Jodi: [Eden, Hedy]


I will provide the classes we already have in the next message