Created
October 30, 2016 15:59
-
-
Save HieronyM/e8a64fca279c404be3ee0a745d366bfe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| import java.util.Vector; | |
| public class Week8 { | |
| public static void main(String args[]) { | |
| Scanner sc = new Scanner(System.in); | |
| Vector kodeKue = new Vector(); | |
| Vector namaKue = new Vector(); | |
| Vector ukuran = new Vector(); | |
| Vector harga = new Vector(); | |
| int pilihan = 0, flag = 0, flag2 = 0; | |
| do{ | |
| String temp=""; | |
| int temp2 = 0, indexUpdate = 0; | |
| System.out.println("\tThe Bliss Cake Price List"); | |
| System.out.println("\t-------------------------"); | |
| System.out.println("1. Show all data"); | |
| System.out.println("2. Insert new data"); | |
| System.out.println("3. Update price"); | |
| System.out.println("4. Delete Data"); | |
| System.out.println("5. Exit"); | |
| do{ | |
| System.out.print("Insert you choice [1..5]: "); | |
| pilihan = sc.nextInt(); | |
| sc.nextLine(); | |
| }while(pilihan < 1 || pilihan > 5); | |
| switch (pilihan) { | |
| case 1: | |
| if(kodeKue.size() > 0) | |
| { | |
| System.out.println("No. Code Cake Name Size Price"); | |
| System.out.println("-----------------------------------------------------------------"); | |
| for (int i = 0; i < kodeKue.size(); i++) { | |
| System.out.println((i+1) + " " + kodeKue.get(i) + " \t" + namaKue.get(i)+" \t" | |
| + ukuran.get(i) + "cm \t" + harga.get(i)); | |
| } | |
| System.out.println(""); | |
| } | |
| else | |
| { | |
| System.out.println("\nThere is no data."); | |
| sc.nextLine(); | |
| } | |
| break; | |
| case 2: | |
| System.out.println("\nInsert new Data"); | |
| System.out.println("---------------"); | |
| // Handle jika memasukkan kode yang sudah pernah | |
| do{ | |
| System.out.print("cake code: "); | |
| temp = sc.nextLine(); | |
| }while(kodeKue.contains(temp)); | |
| kodeKue.add(temp); | |
| System.out.print("Cake name: "); | |
| temp = sc.nextLine(); | |
| namaKue.add(temp); | |
| do{ | |
| flag2 = 0; | |
| System.out.print("Size [10/16/22]: "); | |
| temp2 = sc.nextInt(); | |
| if(temp2 == 10 || temp2 == 16 || temp2 == 22) flag2 = 1; | |
| }while(flag2 == 0); | |
| ukuran.add(temp2); | |
| System.out.print("Cake Price: "); | |
| temp2 = sc.nextInt(); | |
| harga.add(temp2); | |
| System.out.println("Data has been inserted. "); | |
| sc.nextLine(); | |
| break; | |
| case 3: | |
| System.out.println("\nUpdate Cake Price"); | |
| System.out.println("-----------------"); | |
| System.out.print("Insert code cake: "); | |
| temp = sc.nextLine(); | |
| // Handle kodekue yang tidak tersedia | |
| if(kodeKue.contains(temp) == false) | |
| { | |
| System.out.println("Update failed, Data is not found"); | |
| sc.nextLine(); | |
| } | |
| else{ | |
| System.out.print("Insert new price: "); | |
| temp2 = sc.nextInt(); | |
| indexUpdate = kodeKue.indexOf(temp); | |
| harga.set(indexUpdate, temp2); | |
| } | |
| break; | |
| case 4: | |
| System.out.println("\nDelete Cake"); | |
| System.out.println("-----------"); | |
| System.out.print("Insert code cake: "); | |
| temp = sc.nextLine(); | |
| if(kodeKue.contains(temp) == false) | |
| { | |
| System.out.println("Delete data is failed, Data is not found"); | |
| sc.nextLine(); | |
| } | |
| else{ | |
| indexUpdate = kodeKue.indexOf(temp); | |
| kodeKue.remove(indexUpdate); | |
| namaKue.remove(indexUpdate); | |
| ukuran.remove(indexUpdate); | |
| harga.remove(indexUpdate); | |
| System.out.println("Data has been deleted."); | |
| sc.nextLine(); | |
| } | |
| break; | |
| } | |
| }while(pilihan !=5); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment