Valeri173

Domashnoto na Krasi 10-2

Apr 30th, 2020
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main2 {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         Main students = new Main();
  7.         String input="";
  8.  
  9.         while (!input.equals("END")) {
  10.             input = scan.nextLine();
  11.             if (input.equals("ADD")) {
  12.                 System.out.println("The student you want to add: ");
  13.                 int i = scan.nextInt();
  14.                 String n  = scan.next();
  15.                 String m = scan.next();
  16.                 String u = scan.next();
  17.                 String j = i + " " + n + " " + m + " " + u;
  18.                 if(students.contains(j) == false) {
  19.                     students.add(j);
  20.                 }
  21.                 System.out.println();
  22.  
  23.             }else if(input.equals("REM")){
  24.                 System.out.println("The student you want to remove: ");
  25.                 int i = scan.nextInt();
  26.                 String n  = scan.next();
  27.                 String m = scan.next();
  28.                 String u = scan.next();
  29.                 String j = i + " " + n + " " + m + " " + u;
  30.  
  31.                 if(students.contains(j) == true) {
  32.                     students.remove(j);
  33.                 }
  34.                 System.out.println();
  35.             }else if(input.equals("CNT")){
  36.                 System.out.println("\nSize of Dictionary : " + students.getLength());
  37.                 System.out.println();
  38.             }else if(input.equals("PRN")){
  39.                 System.out.println("Now your shopping list contains: ");
  40.                 for (int i = 0; i < students.getLength(); i++) {
  41.                     System.out.println(students.elementAt(i));
  42.                     System.out.println();
  43.                 }
  44.             }
  45.         }
  46.  
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment