Advertisement
Valeri173

Domashnoto na Krasi 6

Feb 14th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main1 {
  4.     public static void main(String[] args){
  5.         CustomArrayList shoppingList = new CustomArrayList();
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         while (true){
  9.             System.out.println();
  10.             System.out.println("For Add choose 1, for Remove choose 2, for End choose 3");
  11.             int choice = scan.nextInt();
  12.  
  13.             if(choice == 1){
  14.                 System.out.println("The element you want to add: ");
  15.                 String n  = scan.next();
  16.  
  17.                 if(shoppingList.contains(n) == false){
  18.                     shoppingList.add(n);
  19.  
  20.                     System.out.println();
  21.                     System.out.println("Now your shopping list contains: ");
  22.                     for (int i = 0; i < shoppingList.getLength(); i++) {
  23.                         System.out.println(shoppingList.elementAt(i));
  24.                     }
  25.  
  26.                     continue;
  27.                 }
  28.             }else if(choice == 2){
  29.  
  30.                 System.out.println("The element you want to remove: ");
  31.                 String n  = scan.next();
  32.  
  33.                 if(shoppingList.contains(n) == true){
  34.                     shoppingList.remove(n);
  35.  
  36.                     System.out.println();
  37.                     System.out.println("Now your shopping list contains: ");
  38.                     for (int i = 0; i < shoppingList.getLength(); i++) {
  39.                         System.out.println(shoppingList.elementAt(i));
  40.                     }
  41.  
  42.                     continue;
  43.                 }
  44.             }else if(choice == 3){
  45.                 break;
  46.             }
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement