Answer this question 
Explain how the constructor in your solution represents the socialNetwork. Describe how you have adapted the DiGraph class so that it contains the same information as in the diagram.

Here are the classes

import java.util.ArrayList;

public class DiGraph
{
    protected int numberOfNodes;
    protected ArrayList<Integer>[] adjacencyList;

    /**
     * Constructor for a directed graphs with a number of nodes but no edges.
     * @param nodes the number of nodes in the graph
     */
    public DiGraph(int nodes) {
        //initialise the number of nodes
        numberOfNodes = nodes;
        //make the array of ArrayLists
        adjacencyList = new ArrayList [nodes];
        //go through each node and make a new ArrayList for that node
        for (int i = 0; i < nodes; i++) {
            adjacencyList[i] = new ArrayList<Integer>();
        }
    }

    /**
     * Add an edge between the two nodes given
     * @param fromNode the node the edge starts from
     * @param toNode the node that the edge goes to
     */
    public void addEdge(int fromNode, int toNode){
        adjacencyList[fromNode].add(toNode);
    }

    /**
     * Return the number of nodes in the graph
     * @return the number of nodes in the graph
     */
    public int getNumberOfNodes() {return numberOfNodes; }

    /**
     * Determine whether there is an edge between the two nodes given
     * @param fromNode the node the edge starts from
     * @param toNode the node that the edge goes to
     * @return true if there is an edge between fromNode and toNode, false otherwise
     */
    public boolean hasEdge(int fromNode, int toNode) {return adjacencyList[fromNode].contains(toNode); }

    /**
     * Print the adjacency list representation of the graph
     */
    public void printAdjacencyList(){
        System.out.println("Number of nodes = "+ numberOfNodes);
        for (int i = 0; i< adjacencyList.length; i++){
            System.out.print("Neighbours of " + i + " : ");
            for (Integer neighbour: adjacencyList[i]) {
                System.out.print(neighbour + " ");
            }
            System.out.println();
        }
    }
}

public class Main {
    public static final String DASHES = new String(new char[80]).replace("\0", "-");

    /**
     * This method creates the graph structure for the social network by adding edges between
     * the nodes (names) in the network. The structure is based on the project brief.
     *
     * @param socialNetwork stores the graph structure
     */
    private static void buildGraph(SocialNetwork socialNetwork) {
        // Add edges between nodes (names) in the social network
        socialNetwork.addEdge(Names.ABEL, Names.CATO);
        socialNetwork.addEdge(Names.BINA, Names.ABEL);
        socialNetwork.addEdge(Names.CATO, Names.ABEL);
        socialNetwork.addEdge(Names.DANA, Names.BINA);
        socialNetwork.addEdge(Names.DANA, Names.CATO);
        socialNetwork.addEdge(Names.DANA, Names.FERN);
        socialNetwork.addEdge(Names.DANA, Names.GENO);
        socialNetwork.addEdge(Names.EDEN, Names.CATO);
        socialNetwork.addEdge(Names.EDEN, Names.DANA);
        socialNetwork.addEdge(Names.EDEN, Names.FERN);
        socialNetwork.addEdge(Names.EDEN, Names.JODY);
        socialNetwork.addEdge(Names.FERN, Names.DANA);
        socialNetwork.addEdge(Names.GENO, Names.FERN);
        socialNetwork.addEdge(Names.GENO, Names.INEZ);
        socialNetwork.addEdge(Names.HEDY, Names.FERN);
        socialNetwork.addEdge(Names.HEDY, Names.JODY);
        socialNetwork.addEdge(Names.INEZ, Names.GENO);
        socialNetwork.addEdge(Names.JODY, Names.INEZ);
    }

    /**
     * Full test for the broadcastTo method
     *
     * @param theSocialNetwork stores the graph structure
     */
    private static void testBroadCastTo(SocialNetwork theSocialNetwork) {
        System.out.println(DASHES);
        System.out.println("broadcastTo test\n");
        for (int i = 0; i < Names.networkMembers.length; i++) {
            System.out.print("Followers of " + Names.networkMembers[i] + ": ");
            System.out.println(theSocialNetwork.broadcastsTo(Names.networkMembers[i]));
        }
        System.out.println();
    }

    /**
     * Full test for the canReach method
     *
     * @param theSocialNetwork stores the graph structure
     */
    private static void canReachTest(SocialNetwork theSocialNetwork) {
        System.out.println(DASHES);
        System.out.println("canReach test\n");
        StringBuilder canReach = new StringBuilder();
        for (int i = 0; i < Names.networkMembers.length; i++) {
            for (int j = 0; j < Names.networkMembers.length; j++) {
                if (j != i && theSocialNetwork.canReach(Names.networkMembers[i], Names.networkMembers[j])) {
                    canReach.append(Names.networkMembers[j]).append(" ");
                }
            }
            if (canReach.length() == 0) {
                canReach = new StringBuilder(" no one!");
            }
            System.out.println(Names.networkMembers[i] + " can reach " + canReach);
            canReach = new StringBuilder();
        }
    }

    /**
     * Full test for the receiversOf method
     *
     * @param theSocialNetwork stores the graph structure
     */
    private static void receiversOfTest(SocialNetwork theSocialNetwork) {
        System.out.println(DASHES);
        System.out.println("receiversOf test\n");
        for (int i = 0; i < Names.networkMembers.length; i++) {
            System.out.print("Receivers of " + Names.networkMembers[i] + ": ");
            System.out.println(theSocialNetwork.receiversOf(Names.networkMembers[i]));
        }
        System.out.println();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        SocialNetwork theSocialNetwork = new SocialNetwork();
        buildGraph(theSocialNetwork);
        testBroadCastTo(theSocialNetwork);

        canReachTest(theSocialNetwork);

        receiversOfTest(theSocialNetwork);
    }
}


import java.util.ArrayList;
import java.util.Arrays;

/**
 * SocialNetwork class extends DiGraph and represents a directed graph of a social network.
 * It provides methods to find followers, check reachability, and find receivers of a person.
 */
public class SocialNetwork extends DiGraph {

    /**
     * Constructor for the SocialNetwork class.
     * Initializes the graph with the number of network members.
     */
    public SocialNetwork() {
        super(Names.networkMembers.length);
    }

    /**
     * Returns a list of followers (direct connections) of the given person.
     *
     * @param person the name of the person whose followers are to be found
     * @return an ArrayList of followers' names
     */
    public ArrayList<String> broadcastsTo(String person) {
        int index = Arrays.asList(Names.networkMembers).indexOf(person);
        ArrayList<String> followers = new ArrayList<>();
        for (Integer node : adjacencyList[index]) {
            followers.add(Names.networkMembers[node]);
        }
        return followers;
    }

    /**
     * Checks if there is a path from the source person to the target person in the social network.
     *
     * @param source the name of the source person
     * @param target the name of the target person
     * @return true if there is a path, false otherwise
     */
    public boolean canReach(String source, String target) {
        int sourceIndex = Arrays.asList(Names.networkMembers).indexOf(source);
        int targetIndex = Arrays.asList(Names.networkMembers).indexOf(target);
        return Traversal.DFS(adjacencyList, sourceIndex, targetIndex);
    }

    /**
     * Returns a list of receivers (all reachable nodes) of the given person.
     *
     * @param person the name of the person whose receivers are to be found
     * @return an ArrayList of receivers' names
     */
    public ArrayList<String> receiversOf(String person) {
        int index = Arrays.asList(Names.networkMembers).indexOf(person);
        ArrayList<Integer> nodeIndexes = Traversal.BFS(adjacencyList, index);
        ArrayList<String> receivers = new ArrayList<>();
        for (Integer node : nodeIndexes) {
            receivers.add(Names.networkMembers[node]);
        }
        return receivers;
    }
}