Nguythang

Ass

Feb 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package ass;
  7.  
  8. /**
  9.  *
  10.  * @author NgT
  11.  */
  12. import java.util.*;
  13.  
  14. public class Ass {
  15.  
  16.     public static int show() {
  17.  
  18.         System.out.println("1. Add new students");
  19.         System.out.println("2. Search for student based on his/her id");
  20.         System.out.println("3. List all of the students");
  21.         System.out.println("4. Delete student based on student id");
  22.         System.out.println("0. Exit");
  23.         String input;
  24.         Scanner in = new Scanner(System.in);
  25.         int a = 0;
  26.         boolean ck = false;
  27.         while (!ck) {
  28.             try {
  29.                 System.out.print("Select your choice: ");
  30.                 a = Integer.parseInt(in.nextLine());
  31.                 if (a > 4 || a < 0) {
  32.                     throw new Exception();
  33.                 }
  34.                 ck = true;
  35.             } catch (Exception e) {
  36.                 System.out.println("Wrong value!!! Retry");
  37.             }
  38.         }
  39.         System.out.println("");
  40.         return a;
  41.     }
  42.  
  43.     public static void main(String[] args) throws Exception{
  44.         // TODO code application logic here
  45.         int choice = -1;
  46.         StudentList s = new StudentList();
  47.         while (choice != 0) {
  48.             choice = show();
  49.             switch (choice) {
  50.                 case 1:
  51.                     s.addNewStudent();
  52.                     break;
  53.                 case 2:
  54.                     s.searchID();
  55.                     break;
  56.                 case 3:
  57.                     s.listAllStudent();
  58.                     break;
  59.                 case 4:
  60.                     s.deleteID();
  61.                     break;
  62.                 default:
  63.                     choice = 0;
  64.             }
  65.  
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment