Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package itse_2457;
- import java.util.Scanner;
- import java.util.StringTokenizer;
- import java.io.*;
- import java.io.*;
- public class Driver
- {
- private int dispatchChoice;
- private int choice;
- public static void main(String[] args)
- {
- File textIn = null;
- Scanner scnr = null;
- int sentinel = 0;
- Rental rent = new Rental();
- Scanner userInput = new Scanner(System.in);
- //saves user choice for dispatch choice
- int dispatchChoice;
- //saves user current choice
- int choice;
- //Prints Main menu
- //Keeps user in the program until they choose to leave
- while( sentinel != -1) {
- printMainMenu();
- choice = userInput.nextInt();
- dispatchChoice = choice;
- //User main menu choice
- dispatchMain(choice);
- //user sub menu choice
- choice = userInput.nextInt();
- //executes user menu choice
- switch(dispatchChoice)
- {
- //File Submenu
- case 0:
- //File Submenu choice
- switch(choice)
- {
- //Import Data
- case 0:
- //Customer Import
- try {
- //creating File instance to reference text file in Java
- textIn = new File("/home/burnthefern/eclipse-workspace/COSC_1336/src/itse_2457/CustomerList.txt");
- //Creating Scanner instance to read File in Java
- scnr = new Scanner(textIn);
- }
- catch (FileNotFoundException e)
- {
- System.out.println(e.getMessage());
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- String line;
- String delimiter = ";";
- String[] splitData = new String[9];
- while(scnr.hasNextLine())
- {
- line = scnr.nextLine();
- String[] splitter = line.split(delimiter);
- for(int ndx = 0; ndx < splitter.length; ndx++)
- splitData[ndx] = splitter[ndx];
- Customer tempCustomer = new Customer(splitData[0], splitData[1], splitData[2], splitData[3]);
- rent.addCustomer(tempCustomer);
- }
- //Movie Import
- try {
- //creating File instance to reference text file in Java
- textIn = new File("/home/burnthefern/eclipse-workspace/COSC_1336/src/itse_2457/MovieList.txt");
- //Creating Scanner instance to read File in Java
- scnr = new Scanner(textIn);
- }
- catch (FileNotFoundException e)
- {
- System.out.println(e.getMessage());
- }
- catch(Exception e)
- {
- System.out.println(e.getMessage());
- }
- while(scnr.hasNextLine())
- {
- line = scnr.nextLine();
- String[] splitDataMovie = new String[5];
- String[] splitter = line.split(delimiter);
- for(int ndx = 0; ndx < splitter.length; ndx++)
- splitDataMovie[ndx] = splitter[ndx];
- int[] movieData = new int[3];
- movieData[0] = Integer.valueOf(splitDataMovie[0]);
- movieData[1] = Integer.valueOf(splitDataMovie[3]);
- movieData[2] = Integer.valueOf(splitDataMovie[4]);
- Movie tempMovie = new Movie(movieData[0], splitDataMovie[1], splitDataMovie[2], movieData[1], movieData[2]);
- rent.addMovie(tempMovie);
- }
- break;
- //Data Export
- case 1:
- break;
- //Return to previous Menu
- case 2:
- break;
- }
- break;
- case 1://Edit Submenu
- switch(choice)
- {
- //Add Customer
- case 0:
- String[] newCustomerInfo = new String[9];
- System.out.println("Please Input customer ID number: ");
- System.out.print(">tkn: ");
- newCustomerInfo[0] = userInput.next();
- System.out.println("\nPlease Input Customer Name: ");
- System.out.print(">: ");
- newCustomerInfo[1] = userInput.next();
- System.out.println("\nPlease input customer address");
- System.out.print(">: ");
- newCustomerInfo[2] = userInput.next();
- System.out.println("\nPlease input customer phone number");
- System.out.print(">: ");
- newCustomerInfo[3] = userInput.next();
- if( newCustomerInfo[0].length() > 0)
- {
- Customer tempCustomer = new Customer(newCustomerInfo[0], newCustomerInfo[1], newCustomerInfo[2], newCustomerInfo[3]);
- rent.addCustomer(tempCustomer);
- }
- else System.out.println("Customer ID must be provided! Customer was not added.");
- //
- // System.out.print("Please input customer ");
- // newCustomerInfo[4] = userInput.nextLine();
- // System.out.print();
- // newCustomerInfo[5] = userInput.nextLine();
- // System.out.print();
- // newCustomerInfo[6] = userInput.nextLine();
- // System.out.print();
- // newCustomerInfo[7] = userInput.nextLine();
- // System.out.print();
- // newCustomerInfo[8] = userInput.nextLine();
- break;
- //Add Movie
- case 1:
- int[] movieData = new int[3];
- String[] movieDataS = new String[2];
- System.out.println("Please enter Movie ID: ");
- System.out.print(">: ");
- movieData[0] = userInput.nextInt();
- System.out.println("\nPlease enter Movie Title:");
- System.out.print(">: ");
- movieDataS[0] = userInput.next(); //might not read entire title
- System.out.println("\nPlease enter Movie Genre: ");
- System.out.print(">: ");
- movieDataS[1] = userInput.next();
- System.out.println("\nPlease enter number of Copies Available: ");
- System.out.print(">: ");
- movieData[1] = userInput.nextInt();
- System.out.println("\nPlease enter number of copies currently checked out: ");
- System.out.print(">: ");
- movieData[2] = userInput.nextInt();
- if(movieData[0] > 0 && movieDataS[0].length() > 0 && movieData[1] > 0)
- {
- Movie tempMovie = new Movie(movieData[0], movieDataS[0], movieDataS[1], movieData[1], movieData[2]);
- rent.addMovie(tempMovie);
- }
- else System.out.println("Missing Information! All movies require the following: "
- + "\n1) Movie ID \n2) Movie Title \n3)Number of copies available");
- break;
- //Update Customer
- case 2:
- String searchID = new String();
- System.out.print("Please enter Customer ID: ");
- searchID = userInput.next();
- int custNdx;
- int choose;
- for(int ndx = 0; ndx < rent.customers.length; ndx++)
- {
- Customer tempCust = rent.customers[ndx];
- String checkID = tempCust.getCustID();
- boolean eqResult = checkID.equals(searchID);
- if(eqResult)
- custNdx = ndx;
- }
- System.out.println("What would you like to update?");
- printUpdateCustomerMenu();
- choose = userInput.nextInt();
- switch(choose)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- }
- break;
- //Update Movie
- case 3:
- break;
- //Delete Customer
- case 4:
- break;
- //Delete Movie
- case 5:
- break;
- //Return to Previous Menu
- case 6:
- break;
- }
- break;
- //View Submenu
- case 2:
- switch(choice)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- }
- break;
- //Sort Submenu
- case 3:
- switch(choice)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- }
- break;
- //RentReturn submenu
- case 4:
- switch(choice)
- {
- case 0:
- break;
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- }
- break;
- //Exit Rent App
- case 5:
- sentinel = -1;
- break;
- }
- }//end of while loop
- }//end of PSVM
- public static void printMainMenu()
- {
- System.out.println("\n Menu");
- System.out.println("========");
- System.out.println("0: File:");
- System.out.println("1: Edit:");
- System.out.println("2: View:");
- System.out.println("3: Sort:");
- System.out.println("4: Rent or Return:");
- System.out.println("5: Exit Rental Application:");
- System.out.print("\nEnter your Choice: ");
- }
- public static void printFileSubMenu()
- {
- System.out.println("\n Sub Menu");
- System.out.println("=======");
- System.out.println("0: Import Data");
- System.out.println("1: Export Data");
- System.out.println("2: Return to Previous Menu");
- System.out.print("\nEnter your choice: ");
- }
- public static void printEditSubMenu()
- {
- System.out.println("\n Sub Menu");
- System.out.println("=======");
- System.out.println("0: Add CUstomer");
- System.out.println("1: Add Movie");
- System.out.println("2: Update Customer");
- System.out.println("3: Update Movie");
- System.out.println("4: Delete Customer");
- System.out.println("5: Delete Movie");
- System.out.println("6: Return to Previous Menu");
- System.out.print("\nEnter your choice: ");
- }
- public static void printViewSubMenu()
- {
- System.out.println("\n Sub Menu");
- System.out.println("=======");
- System.out.println("0: All Customers");
- System.out.println("1: Specific Customer");
- System.out.println("2: All Movies");
- System.out.println("3: Specific Movie");
- System.out.println("4: Specific Genre");
- System.out.println("5: Return to Previous Menu");
- System.out.print("\nEnter your choice: ");
- }
- public static void printSortSubMenu()
- {
- System.out.println("\n Sub Menu");
- System.out.println("=======");
- System.out.println("0: Sort Customer by Name");
- System.out.println("1: Sort Customer by CustID");
- System.out.println("2: Sort Movie by Title");
- System.out.println("3: Sort Movie by Genre");
- System.out.print("\nEnter your choice: ");
- }
- public static void printRentReturnSubMenu()
- {
- System.out.println("\n Sub Menu");
- System.out.println("======");
- System.out.println("0: Return a Movie");
- System.out.println("1: Rent a Movie");
- System.out.println("2: Return to Previous Menu");
- System.out.print("\nEnter your choice: ");
- }
- public static void printUpdateCustomerMenu()
- {
- System.out.println("\n Customer Updater");
- System.out.println("=======");
- System.out.println("0: Update Customer ID");
- System.out.println("1: Update Customer Name");
- System.out.println("2: Update Customer Address");
- System.out.println("3: Update Customer Phone Number");
- System.out.println("4: Return to Previous Menu");
- System.out.print("\nEnter your choice: ");
- }
- //Determines user choice and navigates to appropriate menu
- //based on user choice
- public static void dispatchMain(int choice)
- {
- switch(choice)
- {
- case 0:
- printFileSubMenu();
- break;
- case 1:
- printEditSubMenu();
- break;
- case 2:
- printViewSubMenu();
- break;
- case 3:
- printSortSubMenu();
- break;
- case 4:
- printRentReturnSubMenu();
- break;
- case 5:
- System.out.println("Goodbye!");
- break;
- }
- }
- }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement