Facebook
From Sexy Lemur, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 101
  1. package prison;
  2.  
  3. import java.util.InputMismatchException;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Main main = new Main();
  9.         Scanner scanner = new Scanner(System.in);
  10.         Prison prison = new Prison();
  11.         boolean close = false;
  12.         int menuChoice = 0;
  13.  
  14.         while (!close) {
  15.             menuChoice = main.menuScreen(scanner);
  16.             if (menuChoice == 1) {
  17.                 prison.printPrisoners();
  18.             } else if (menuChoice == 2) {
  19.             } else if (menuChoice == 3) {
  20.                 prison.removePrisoner(scanner);
  21.             } else if (menuChoice == 4) {
  22.  
  23.             } else if (menuChoice == 5) {
  24.                 prison.loadFile(scanner);
  25.             } else if (menuChoice == 6) {
  26.                 System.out.println("Exiting program");
  27.                 close = true;
  28.             }
  29.         }
  30.     }
  31.  
  32.     public int menuScreen(Scanner scanner) {
  33.         boolean inputWrong = false;
  34.  
  35.         while (!inputWrong) {
  36.             try {
  37.                 System.out.println("*******************");
  38.                 System.out.println("1) Print prisoners ");
  39.                 System.out.println("2) Add prisoner ");
  40.                 System.out.println("3) Remove prisoner ");
  41.                 System.out.println("4) Save prisoners ");
  42.                 System.out.println("5) Load prisoners ");
  43.                 System.out.println("6) Close program");
  44.                 System.out.println();
  45.                 System.out.println("Please choose an option");
  46.  
  47.                 int choice = scanner.nextInt();
  48.                 if (choice > 0 && choice < 7) {
  49.                     return choice;
  50.                 } else {
  51.                     System.out.println("Wrong input, please try again");
  52.                     inputWrong = true;
  53.                 }
  54.             } catch (InputMismatchException e) {
  55.                 scanner.next();
  56.                 System.out.println("Please try again");
  57.             }
  58.         }
  59.         return 0;
  60.     }
  61. }
  62.