Java and Data Structures

As part of my Data Structures unit (ITC322) at Charles Sturt University I built a rudimentary console based social network in Java.

One of the code files which shows my understanding of java and also the data structures involved which coudl be handy for worrking at webgames Inc.

Java File>

// import java.io.FileNotFoundException;
          import java.util.Scanner;

          /**
          * Driver program for the social network application.
          * Presents a menu for all of the socialNetwork class methods and operations.
          */
          public class Main {

          /**
          * Loads default network files on startup then runs the menu while loop.
          */
          public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
          SocialNetwork network = new SocialNetwork();

          // Attempt to load default files.
          try {
          network.loadFromFiles("index.txt", "friend.txt");
          } catch (FileNotFoundException e) {
          System.err
          .println("Could not load default files load a network from the menu first before selecting other
          options..");
          }

          // This loops constantly promoting user to make a choice from the menu.
          boolean running = true;
          while (running) {
          printMenu();
          String choice = scanner.nextLine();

          switch (choice) {
          case "1":
          running = false;
          break;
          case "2":
          loadNetwork(scanner, network);
          break;
          case "3":
          promptFriendList(scanner, network);
          break;
          case "4":
          promptFriendsOfFriends(scanner, network);
          break;
          case "5":
          promptCommonFriends(scanner, network);
          break;
          case "6":
          promptDeleteMember(scanner, network);
          break;
          case "7":
          network.listByPopularity();
          break;
          default:
          System.out.println("Not a valid choice Please enter 1-7.");
          }
          }
          scanner.close();
          }

          // prints the main menue options
          private static void printMenu() {
          System.out.println("\nSocial Network Menu");
          System.out.println("1. Exit");
          System.out.println("2. Load new network from files");
          System.out.println("3. List friends of a person");
          System.out.println("4. List friends and friends of friends");
          System.out.println("5. List common friends of two people");
          System.out.println("6. Delete a member");
          System.out.println("7. List all members by popularity");
          System.out.print("Choose an option (1-7): ");
          }

          /**
          * Prompts for two filenames and loads a new network, replacing the current one
          *
          * @param scanner to read the files names inputed by user.
          * @param network to load file detail into.
          *
          */
          private static void loadNetwork(Scanner scanner, SocialNetwork network) {
          System.out.print("Enter index filename: ");
          String indexFile = scanner.nextLine();
          System.out.print("Enter friend filename: ");
          String friendFile = scanner.nextLine();
          try {
          network.loadFromFiles(indexFile, friendFile);
          } catch (FileNotFoundException e) {
          System.err.println("Error: Could not find one or both of the file names");
          }
          }

          /**
          * Prompts for a name and lists that person's friends.
          *
          * @param scanner to read name inputed by user.
          * @param network that is queried.
          */
          private static void promptFriendList(Scanner scanner, SocialNetwork network) {
          System.out.print("Enter a name: ");
          network.friendList(scanner.nextLine());
          }

          /**
          * Prompts for a name and lists their friends and their friends of friends.
          *
          * @param scanner to read name inputed by user.
          * @param network which is queried from.
          */
          private static void promptFriendsOfFriends(Scanner scanner, SocialNetwork network) {
          System.out.print("Enter a name: ");
          network.friendsOfFriends(scanner.nextLine());
          }

          /**
          * Prompts for two names and lists the friends they have in common.
          *
          * @param scanner to read the two names inputed by user.
          * @param network which is quried from.
          */
          private static void promptCommonFriends(Scanner scanner, SocialNetwork network) {
          System.out.print("Enter first name: ");
          String nameA = scanner.nextLine();
          System.out.print("Enter second name: ");
          String nameB = scanner.nextLine();
          network.commonFriends(nameA, nameB);
          }

          /**
          * Prompts for a name and deletes the person with that name from the network.
          *
          * @param scanner to read the inputed name by user.
          * @param network which is quried from.
          */
          private static void promptDeleteMember(Scanner scanner, SocialNetwork network) {
          System.out.print("Enter name to delete that person from the netwrok: ");
          network.deleteMember(scanner.nextLine(), scanner);
          }
          }