Vasilena

ТЕМА СТРУКТУРИ ОТ ДАННИ 2

Mar 8th, 2021 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. //TEМА 16 Classwork 08.03.21//
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class UASD_2_080321 {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         ArrayList<String> list = new ArrayList<>();
  10.         String answer = "";
  11.  
  12.         while (!answer.equals("end")){
  13.             System.out.println("Please, enter your choice: <add><rem><prn><end>");
  14.             answer = sc.nextLine();
  15.             if(answer.equals("add") ){
  16.                 System.out.println("Please, enter the name you'd like to add! ");
  17.                 String name = sc.nextLine();
  18.                 list.add(name);
  19.             }else if(answer.equals("rem")){
  20.                 System.out.println("If you want to remove by number enter <num>. If you want to remove by name enter <name>! ");
  21.                 String choice = sc.nextLine();
  22.                 if(choice.equals("num")){
  23.                     System.out.println("Please, enter the number you'd like to remove! ");
  24.                     int number = sc.nextInt();
  25.                     list.remove(number - 1);
  26.                 }else if(choice.equals("name")){
  27.                     System.out.println("Please, enter the name you'd like to remove! ");
  28.                     String nametoremove = sc.nextLine();
  29.                     list.remove(new String(nametoremove));
  30.                 }
  31.             }else if(answer.equals("prn")){
  32.                 System.out.println("Your list:" + list);
  33.             }
  34.         }
  35.         System.out.println("The program has ended! ");
  36.  
  37.     }
  38. }
  39.  
Add Comment
Please, Sign In to add comment