Kriss_7777

StaticArrayList_Main

Feb 13th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. package StaticArayList;
  2. //package exTwo;
  3.  
  4. // ВИКТОР
  5.  
  6. import java.util.Scanner;
  7.  
  8. public class StaticArrayList_Main {
  9.  
  10.     public static void main(String[] args)
  11.     {
  12.        
  13.         StaticArrayList_Methods shoppingList = new StaticArrayList_Methods();
  14.         Scanner sc=new Scanner(System.in);
  15.        
  16.         while(true)
  17.         {
  18.             System.out.println();
  19.             System.out.println("For ADD choose 1, for REMOVE choose 2, for END choose 3");
  20.             int choice=sc.nextInt();
  21.            
  22.             if(choice==1)
  23.             {
  24.                 System.out.println("The element you want to add:");
  25.                 String n=sc.next();
  26.                
  27.                 if(shoppingList.contains(n)==false)
  28.                 {
  29.                     shoppingList.add(n);
  30.                    
  31.                     System.out.println();
  32.                     System.out.println("Now your list contains:");
  33.                     getList(shoppingList);
  34.                    
  35.                     continue;
  36.                    
  37.                 } else
  38.                 {
  39.                     System.out.println("The element is already in the list");
  40.                     continue;
  41.                 }
  42.             }
  43.            
  44.             if(choice==2)
  45.             {
  46.                 System.out.println("The element you want to remove:");
  47.                 String n=sc.next();
  48.                
  49.                 if(shoppingList.contains(n))
  50.                 {
  51.                     shoppingList.remove(shoppingList.indexOf(n));
  52.                    
  53.                     System.out.println();
  54.                     System.out.println("Now your list contains:");
  55.                     getList(shoppingList);
  56.                    
  57.                     continue;
  58.                    
  59.                 } else
  60.                 {
  61.                     System.out.println("No element to remove");
  62.                     continue;
  63.                 }
  64.             }
  65.            
  66.             if(choice==3)
  67.             {
  68.                 System.out.println();
  69.                 System.out.println("Now your list contains:");
  70.                 getList(shoppingList);
  71.                
  72.                 System.out.println("Program ended");
  73.                 break;
  74.             }
  75.            
  76.            
  77.         } // end while
  78.        
  79.         sc.close();
  80.        
  81.     } // end MAIN
  82.    
  83.    
  84.    
  85.     static void getList(StaticArrayList_Methods shoppingList)
  86.     {
  87.         for(int i=0; i<shoppingList.getLength(); i++)
  88.         {
  89.             System.out.println(shoppingList.elementAt(i));
  90.         }
  91.     }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment