Advertisement
akevintg

AOOP_Assignment1

Oct 9th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AOOP_Assignment1{
  4.     public static void main(String[] args) {
  5.         Scanner input=new Scanner(System.in);
  6.         String nama;
  7.         int money;
  8.         enter();
  9.         do{
  10.             System.out.print("Input Your Name [3...20]      : ");
  11.             nama=input.nextLine();
  12.         }while(nama.length()<3||nama.length()>20);
  13.         do{
  14.             System.out.print("Input Your money [0...1000]      : ");
  15.             money=input.nextInt();
  16.         }while(money<0||money>1000);
  17.         enter();
  18.         System.out.println("Hi, "+nama+"!");
  19.         System.out.println("Welcome to Bluejack's Food Corner");
  20.         input.nextLine();input.nextLine();
  21.         int pil;
  22.         do{
  23.             enter();
  24.             System.out.println("Bluejack's Food Corner");
  25.             System.out.println("========================");
  26.             System.out.println("1. Buy Food");
  27.             System.out.println("2. Add More Money");
  28.             System.out.println("3. Exit");
  29.             System.out.print("Choose : ");
  30.             pil=input.nextInt();
  31.             switch(pil){
  32.                 case 1:
  33.                     money=buy(money);
  34.                     break;
  35.                 case 2:
  36.                     money=addMoney(money);
  37.                     break;
  38.                 case 3:
  39.                     System.out.println(" ");
  40.                     System.out.println("Prepare and keep the Spirit in you! ^^");
  41.                     System.out.println("Press any key to continue . . .");
  42.                     input.nextLine();input.nextLine();
  43.                     break;
  44.             }
  45.         }while(pil!=3);
  46.        
  47.     }
  48.     public static void enter(){
  49.         for (int i = 0; i < 25; i++) {
  50.             System.out.println("");
  51.         }
  52.     }
  53.     public static int buy(int money){
  54.         enter();
  55.         Scanner input=new Scanner(System.in);
  56.         System.out.println("Code    Food Name   Price");
  57.         System.out.println("====================================");
  58.         System.out.println("CC  Chocolate Cake  $50");
  59.         System.out.println("SC  Strawberry Cheese Cake  $100");
  60.         System.out.println("OP  Orange Pie  $60");
  61.         System.out.println("BM  Blueberry Muffin    $120");
  62.         System.out.println("MI  Mango Ice Cream $40");
  63.         System.out.println("Your Current Money : $"+money);
  64.         String pilih;
  65.         int flag=0;
  66.         do{
  67.             System.out.print("Input the Food Code [Capital Letter][EX to cancel] : ");
  68.             pilih=input.next();
  69.             //pilih=pilih.toUpperCase();//supaya bisa CC = cc
  70.             if(pilih.equals("CC")||pilih.equals("SC")||pilih.equals("OP")||
  71.                     pilih.equals("BM")||pilih.equals("MI")||pilih.equals("EX"))
  72.                 flag++;
  73.         }while(flag==0);
  74.         if(pilih.equals("EX"))
  75.             System.out.println("Back To Menu");
  76.         else {
  77.             if(pilih.equals("CC"))
  78.                     if(money<50)
  79.                         System.out.println("Sorry Not Enough Money");
  80.                     else {
  81.                         money-=50;
  82.                         System.out.println("Thank You for Buying Chocolate Cake for $50 ^^");
  83.                         System.out.println("Your current money : $"+money);
  84.                     }
  85.             else if(pilih.equals("SC"))
  86.                     if(money<100)
  87.                         System.out.println("Sorry Not Enough Money");
  88.                     else {
  89.                         money-=100;
  90.                         System.out.println("Thank You for Buying Strawberry Cheese Cake for $100 ^^");
  91.                         System.out.println("Your current money : $"+money);
  92.                     }
  93.             else if(pilih.equals("OP"))
  94.                     if(money<60)
  95.                         System.out.println("Sorry Not Enough Money");
  96.                     else {
  97.                         money-=60;
  98.                         System.out.println("Thank You for Buying Orange Pie for $60 ^^");
  99.                         System.out.println("Your current money : $"+money);
  100.                     }
  101.             else if(pilih.equals("BM"))
  102.                     if(money<120)
  103.                         System.out.println("Sorry Not Enough Money");
  104.                     else {
  105.                         money-=120;
  106.                         System.out.println("Thank You for Buying Blueberry Muffin for $120 ^^");
  107.                         System.out.println("Your current money : $"+money);
  108.                     }
  109.             else
  110.                     if(money<40)
  111.                         System.out.println("Sorry Not Enough Money");
  112.                     else {
  113.                         money-=40;
  114.                         System.out.println("Thank You for Buying Mango Ice Cream for $40 ^^");
  115.                         System.out.println("Your current money : $"+money);
  116.                     }
  117.         }
  118.         input.nextLine();input.nextLine();
  119.         return money;
  120.     }
  121.     public static int addMoney(int money){
  122.         enter();
  123.         System.out.println("Your Current Money is $"+money);
  124.         Scanner input=new Scanner(System.in);
  125.         int add;
  126.         do{
  127.             System.out.print("Input Amount of Money you want to add [0..."+(1000-money)+"] :");
  128.             add=input.nextInt();
  129.         }while(add+money>1000||add<0);
  130.         money+=add;
  131.         System.out.println("Succesfully add more money ^^");
  132.         System.out.println("Your Current Money is $"+money);
  133.         input.nextLine();input.nextLine();
  134.         return money;
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement