code

Download Code

If you can't read please download the document

Upload: ray-ray

Post on 20-Aug-2015

69 views

Category:

Education


2 download

TRANSCRIPT

  1. 1. import java.util.Scanner; public class FruitStore{ static Scanner in = new Scanner(System.in); static String nama, code, product; static int pilih, qty, harga; static char yn; public static void clear() { for(int i=0;i 10); System.out.print("nnnnnnThank you for buying ^^n"); if(code.equals("ora")){ product = "Orange"; harga = 10000; }else if(code.equals("app")){ product = "Apple"; harga = 12000; }else if(code.equals("gra")){
  2. 2. product = "Grape"; harga = 14000; } System.out.print("You have bought "+qty+" kg "+product+" @"+harga+"n"); System.out.print("Total : "+ harga * qty); in.nextLine(); } public static void menu2(){ System.out.print("BUY JUICEnn"); System.out.print("+==========================================+n"); System.out.print("|Item |Price |Code|n"); System.out.print("+==========================================+n"); System.out.print("|Apple juice |Rp. 4500 |appj|n"); System.out.print("|Orange juice |Rp. 5000 |oraj|n"); System.out.print("|Grape juice |Rp. 5500 |graj|n"); System.out.print("+==========================================+n"); do{ System.out.print("Input code : "); code = in.next(); }while(!code.equals("oraj") && !code.equals("graj") && ! code.equals("appj") ); do{ try{ System.out.print("Input quantity [1..10] : "); qty = in.nextInt(); }catch(Exception e){ qty = 0; in.nextLine(); } }while(qty < 1 || qty > 10); System.out.print("nnnnnnThank you for buying ^^n"); if(code.equals("oraj")){ product = "Orange"; harga = 5000; }else if(code.equals("appj")){ product = "Apple"; harga = 4500; }else if(code.equals("graj")){ product = "Grape"; harga = 5500; } System.out.print("You have bought "+qty+" cup "+product+" juice @"+harga+"n"); System.out.print("Total : "+ harga * qty); in.nextLine(); } public static void main(String args[]) { System.out.printf("%40snnnnn","BEGH Fruit 'n Juice Store"); do { System.out.print("Please input your name [5..30] : "); nama = in.nextLine(); }while( nama.length() < 5 || nama.length() > 30);
  3. 3. do{ clear(); menu(); try{ pilih = in.nextInt(); }catch(Exception e){ pilih = -1; in.nextLine(); } switch(pilih){ case 1: menu1(); break; case 2: menu2(); break; } if(pilih != 3){ do{ System.out.print("nContinue shopping [Y/N] : "); yn = in.nextLine().charAt(0); }while(yn != 'Y' && yn != 'N' && yn != 'y' && yn != 'n'); }else{ yn = 'N'; } }while(yn == 'Y' || yn == 'y'); System.out.print("nTerima kasih, datang kembalin"); System.out.print("nB-Linen"); in.nextLine(); } }