Advertisement
Guest User

Main

a guest
Mar 24th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. public class Main {
  3.     Scanner sc = new Scanner(System.in);
  4.     Vector<Smartphone> vSmart = new Vector<>();
  5.     Vector<Cellphone> vCell = new Vector<>();
  6.    
  7.     String nama="",os="",touchscreen="";
  8.     int memory=0,price=0,pilih=0,type=0;
  9.    
  10.     Main(){
  11.         do {
  12.             System.out.println(" ============================");
  13.             System.out.println(" | Welcome to Phone Creator |");
  14.             System.out.println("============================");
  15.             System.out.println(" 1. Create Phone");
  16.             System.out.println(" 2. Delete All Phone");
  17.             System.out.println(" 3. View All Phone");
  18.             System.out.println(" 4. Exit");
  19.             System.out.print(" Choose :");
  20.             pilih = sc.nextInt(); sc.nextLine();
  21.             if (pilih ==1) {
  22.                 System.out.println(" 1. SmartPhone");
  23.                 System.out.println(" 2. CellPhone");
  24.                 System.out.print(" Choose :");
  25.                 type = sc.nextInt(); sc.nextLine();
  26.                 if (type == 1) {
  27.                     do {
  28.                         System.out.print(" Input Phone Name [5..20] :");
  29.                         nama = sc.nextLine();
  30.                     }while(nama.length() <5 || nama.length() >20 );
  31.                     do {
  32.                         System.out.print(" Input Operating System [IOS | Android | WindowsPhone] :");
  33.                         os = sc.nextLine();
  34.                         if(os.equals("IOS")) {
  35.                             price =2000000 + (memory *1000);
  36.                         }
  37.                         else if(os.equals("Android")) {
  38.                             price =1500000 + (memory *1000);
  39.                         }
  40.                         else {
  41.                             price = 1000000 + (memory*1000);
  42.                         }
  43.                     }while(!os.equals("IOS") && !os.equals("Android") && !os.equals("WindowsPhone"));
  44.                     do {
  45.                         System.out.println(" Input Memory [8 | 16 | 32 | 64] :");
  46.                         memory = sc.nextInt(); sc.nextLine();
  47.                     }while(memory !=8 && memory!=16 && memory!=16 && memory!=62);
  48.                     do {
  49.                         System.out.println(" Touchscreen [Y/N]? :");
  50.                         touchscreen = sc.nextLine();
  51.                     }while(!touchscreen.equals("Y") && !touchscreen.equals("N"));
  52.                    
  53.                     System.out.print(" Success create new phone!");
  54.                     sc.nextLine();
  55.                    
  56.                     Smartphone a = new Smartphone(nama,os,memory,price,touchscreen);
  57.                     vSmart.add(a);
  58.                 }
  59.                    
  60.                 else {
  61.                     do {
  62.                         System.out.println(" Input Phone Name [5..20] :");
  63.                         nama = sc.nextLine();
  64.                     }while(nama.length() <5 || nama.length() >20 );
  65.                     do {
  66.                         System.out.println("Input Operating System [Symbian | Bada] :");
  67.                         os = sc.nextLine();
  68.                         if(os.equals("Symbian")) {
  69.                             price =800000 + (memory *1000);
  70.                         }
  71.                         else {
  72.                             price = 650000 + (memory*1000);
  73.                         }
  74.                     }while(!os.equals("Symbian") && !os.equals("Bada"));
  75.                     do {
  76.                         System.out.println(" Input Memory [8 | 16 | 32 | 64] :");
  77.                         memory = sc.nextInt(); sc.nextLine();
  78.                     }while(memory !=8 && memory!=16 && memory!=16 && memory!=62);
  79.                    
  80.                     System.out.print(" Success create new phone!");
  81.                     sc.nextLine();
  82.                    
  83.                     Cellphone a = new Cellphone(nama,os,memory,price);
  84.                     vCell.add(a);      
  85.                 }  
  86.                
  87.             }
  88.            
  89.             else if (pilih == 2) {
  90.                 if (vSmart.isEmpty() && vCell.isEmpty() ) {
  91.                     System.out.println("NO DATA");
  92.                 }
  93.                 else {
  94.                     vSmart.clear();
  95.                     vCell.clear();
  96.                     System.out.println("DATA KEHAPUS");
  97.                     sc.nextLine();
  98.                 }
  99.             }
  100.            
  101.             else if (pilih == 3) {
  102.                 if (vSmart.isEmpty() && vCell.isEmpty() ) {
  103.                     System.out.println("NO DATA");
  104.                 }
  105.                 else {
  106.                     for(int i=0; i<vSmart.size(); i++) {
  107.                         System.out.println((i+1)+" "+vSmart.get(i).getNama()+" "+vSmart.get(i).getOs()+" "+vSmart.get(i).getMemory()+" "+vSmart.get(i).getPrice()+" "+vSmart.get(i).getTouchscreen());
  108.                     }
  109.                     for(int i=0; i<vCell.size(); i++) {
  110.                         System.out.println((i+1)+" "+vCell.get(i).getNama()+" "+vCell.get(i).getOs()+" "+vCell.get(i).getMemory()+" "+vCell.get(i).getPrice());
  111.                     }
  112.                     sc.nextLine();
  113.                 }
  114.             }
  115.  
  116.            
  117.            
  118.            
  119.         }while(pilih !=4);
  120.        
  121.     }
  122.  
  123.     public static void main(String[] args) {
  124.         new Main();
  125.  
  126.     }
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement