Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AOOP_Assignment1{
- public static void main(String[] args) {
- Scanner input=new Scanner(System.in);
- String nama;
- int money;
- enter();
- do{
- System.out.print("Input Your Name [3...20] : ");
- nama=input.nextLine();
- }while(nama.length()<3||nama.length()>20);
- do{
- System.out.print("Input Your money [0...1000] : ");
- money=input.nextInt();
- }while(money<0||money>1000);
- enter();
- System.out.println("Hi, "+nama+"!");
- System.out.println("Welcome to Bluejack's Food Corner");
- input.nextLine();input.nextLine();
- int pil;
- do{
- enter();
- System.out.println("Bluejack's Food Corner");
- System.out.println("========================");
- System.out.println("1. Buy Food");
- System.out.println("2. Add More Money");
- System.out.println("3. Exit");
- System.out.print("Choose : ");
- pil=input.nextInt();
- switch(pil){
- case 1:
- money=buy(money);
- break;
- case 2:
- money=addMoney(money);
- break;
- case 3:
- System.out.println(" ");
- System.out.println("Prepare and keep the Spirit in you! ^^");
- System.out.println("Press any key to continue . . .");
- input.nextLine();input.nextLine();
- break;
- }
- }while(pil!=3);
- }
- public static void enter(){
- for (int i = 0; i < 25; i++) {
- System.out.println("");
- }
- }
- public static int buy(int money){
- enter();
- Scanner input=new Scanner(System.in);
- System.out.println("Code Food Name Price");
- System.out.println("====================================");
- System.out.println("CC Chocolate Cake $50");
- System.out.println("SC Strawberry Cheese Cake $100");
- System.out.println("OP Orange Pie $60");
- System.out.println("BM Blueberry Muffin $120");
- System.out.println("MI Mango Ice Cream $40");
- System.out.println("Your Current Money : $"+money);
- String pilih;
- int flag=0;
- do{
- System.out.print("Input the Food Code [Capital Letter][EX to cancel] : ");
- pilih=input.next();
- //pilih=pilih.toUpperCase();//supaya bisa CC = cc
- if(pilih.equals("CC")||pilih.equals("SC")||pilih.equals("OP")||
- pilih.equals("BM")||pilih.equals("MI")||pilih.equals("EX"))
- flag++;
- }while(flag==0);
- if(pilih.equals("EX"))
- System.out.println("Back To Menu");
- else {
- if(pilih.equals("CC"))
- if(money<50)
- System.out.println("Sorry Not Enough Money");
- else {
- money-=50;
- System.out.println("Thank You for Buying Chocolate Cake for $50 ^^");
- System.out.println("Your current money : $"+money);
- }
- else if(pilih.equals("SC"))
- if(money<100)
- System.out.println("Sorry Not Enough Money");
- else {
- money-=100;
- System.out.println("Thank You for Buying Strawberry Cheese Cake for $100 ^^");
- System.out.println("Your current money : $"+money);
- }
- else if(pilih.equals("OP"))
- if(money<60)
- System.out.println("Sorry Not Enough Money");
- else {
- money-=60;
- System.out.println("Thank You for Buying Orange Pie for $60 ^^");
- System.out.println("Your current money : $"+money);
- }
- else if(pilih.equals("BM"))
- if(money<120)
- System.out.println("Sorry Not Enough Money");
- else {
- money-=120;
- System.out.println("Thank You for Buying Blueberry Muffin for $120 ^^");
- System.out.println("Your current money : $"+money);
- }
- else
- if(money<40)
- System.out.println("Sorry Not Enough Money");
- else {
- money-=40;
- System.out.println("Thank You for Buying Mango Ice Cream for $40 ^^");
- System.out.println("Your current money : $"+money);
- }
- }
- input.nextLine();input.nextLine();
- return money;
- }
- public static int addMoney(int money){
- enter();
- System.out.println("Your Current Money is $"+money);
- Scanner input=new Scanner(System.in);
- int add;
- do{
- System.out.print("Input Amount of Money you want to add [0..."+(1000-money)+"] :");
- add=input.nextInt();
- }while(add+money>1000||add<0);
- money+=add;
- System.out.println("Succesfully add more money ^^");
- System.out.println("Your Current Money is $"+money);
- input.nextLine();input.nextLine();
- return money;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement