Complete a new class for this scenario called SocialNetwork Create a class called…
- User
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 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[] adjList, Integer startNode) Refactored method header: public static boolean DFS(ArrayList[] 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[] adjList, Integer startNode) Refactored method header: public static ArrayList BFS(ArrayList[] 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 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]
- Assistant
- User
- Assistant
- User
I am getting these 4 errors Cannot resolve symbol 'edges' Cannot resolve method 'getAdjNodes' in 'SocialNetwork' Cannot resolve symbol 'adjList' Cannot resolve symbol 'adjList'
- Assistant
- User
we can only edit the classes and methods mentioned in the description
- Assistant
- User
I still have this problem here Cannot resolve symbol 'edges' public SocialNetwork() { super(Names.networkMembers.length); for (int[] edge : Names.edges) { addEdge(edge[0], edge[1]); } }
- Assistant
I apologize for the confusion. In the given scenario, we cannot modify the Names class to directly include the "edges" variable. However, you can create the "edges" array in the SocialNetwork class constructor like this:
public class SocialNetwork extends DiGraph { public SocialNetwork() { super(Names.networkMembers.length); int[][] edges = { {Names.ABEL, Names.CATO}, {Names.BINA, Names.ABEL}, {Names.CATO, Names.ABEL}, {Names.DANA, Names.BINA}, {Names.DANA, Names.CATO}, {Names.DANA, Names.FERN}, {Names.DANA, Names.GENO}, {Names.EDEN, Names.CATO}, {Names.EDEN, Names.DANA}, {Names.EDEN, Names.FERN}, {Names.EDEN, Names.JODY}, {Names.FERN, Names.DANA}, {Names.GENO, Names.FERN}, {Names.GENO, Names.INEZ}, {Names.HEDY, Names.FERN}, {Names.HEDY, Names.JODY}, {Names.INEZ, Names.GENO}, {Names.JODY, Names.INEZ} }; for (int[] edge : edges) { addEdge(edge[0], edge[1]); } } ... } - User
Also complete this function in the main class public static final String DASHES = new String(new char[80]).replace("\0", "-"); /** * COMPLETE THIS METHOD to create the graph structure shown in the project brief * @param socialNetwork stores the graph structure */ private static void buildGraph(SocialNetwork socialNetwork) {
} - Assistant
Since you have already added edges directly to the SocialNetwork constructor, there is no need to use the
buildGraphmethod in the Main class. If you still want to keep the method and use it to create the graph connections, remove the edges from the constructor and use the buildGraph method in the Main class's main function.Here's how you would write the SocialNetwork constructor without adding edges:
public class SocialNetwork extends DiGraph { public SocialNetwork() { super(Names.networkMembers.length); } ... }Now, update the buildGraph method in the Main class to create the connections:
public static final String DASHES = new String(new char[80]).replace("\0", "-"); /** * COMPLETE THIS METHOD to create the graph structure shown in the project brief * @param socialNetwork stores the graph structure */ private static void buildGraph(SocialNetwork socialNetwork) { int[][] edges = { {Names.ABEL, Names.CATO}, {Names.BINA, Names.ABEL}, {Names.CATO, Names.ABEL}, {Names.DANA, Names.BINA}, {Names.DANA, Names.CATO}, {Names.DANA, Names.FERN}, {Names.DANA, Names.GENO}, {Names.EDEN, Names.CATO}, {Names.EDEN, Names.DANA}, {Names.EDEN, Names.FERN}, {Names.EDEN, Names.JODY}, {Names.FERN, Names.DANA}, {Names.GENO, Names.FERN}, {Names.GENO, Names.INEZ}, {Names.HEDY, Names.FERN}, {Names.HEDY, Names.JODY}, {Names.INEZ, Names.GENO}, {Names.JODY, Names.INEZ} }; for (int[] edge : edges) { socialNetwork.addEdge(edge[0], edge[1]); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.