62,612
社区成员
发帖
与我相关
我的任务
分享
public class StarBuzzCoffee {
Scanner scan=new Scanner(System.in);
public static void main(String[] args){
Beverage b = null;
StarBuzzCoffee sc=new StarBuzzCoffee();
sc.chooseCoffee(b);
}
//选择咖啡
public void chooseCoffee(Beverage b){
System.out.println("請選擇:");
System.out.println("1--> Empresso");
System.out.println("2--> HousBlend");
System.out.println("-----------------------");
int i=scan.nextInt();
if(i==1){
b=new Espresso();
chooseCondiment(b);
}
if(i==2){
b=new HousBlend();
chooseCondiment(b);
}
else{
System.out.println("-----------------------");
System.out.println("對不起!沒有你選擇的coffee");
chooseCoffee(b);
}
}
//调料选择
public void chooseCondiment(Beverage b){
System.out.println("-----------------------");
System.out.println("請選擇調料:");
System.out.println("1--> Mocha");
System.out.println("2--> Milk");
System.out.println("3--> Don't Anything");
System.out.println("-----------------------");
// Scanner scan=new Scanner(System.in);
int i=scan.nextInt();
if(i==1){
b=new Mocha(b);
accounts(b);
}
if(i==2){
b=new Milk(b);
accounts(b);
}
else{
System.out.println("你好!你购买的coffee是:");
System.out.println(b.getDescription());
System.out.println("总共是:" + b.cost());
}
}
//结账
public void accounts(Beverage b){
System.out.println("-----------------------");
System.out.println("是否继续选择调料");
System.out.println("1--> yes");
System.out.println("2--> no");
System.out.println("-----------------------");
// Scanner scan=new Scanner(System.in);
int i=scan.nextInt();
if(i==1){
chooseCondiment(b);
}
else{
System.out.println("你好!你购买的coffee是--:");
System.out.println(b.getDescription());
System.out.println("总共是:" + b.cost());
}
}
}
請選擇:
1--> Empresso
2--> HousBlend
-----------------------
1
-----------------------
請選擇調料:
1--> Mocha
2--> Milk
3--> Don't Anything
-----------------------
1
-----------------------
是否继续选择调料
1--> yes
2--> no
-----------------------
2
你好!你购买的coffee是--:
coffer: Espresso1.9
Mocha: 2.0
总共是:3.9
你好!你购买的coffee是:
coffer: Espresso1.9
Mocha: 2.0
总共是:3.9
-----------------------
對不起!沒有你選擇的coffee
請選擇:
1--> Empresso
2--> HousBlend
-----------------------
if(i==1){
b=new Mocha(b);
accounts(b);
}else
if(i==2){
b=new Milk(b);
accounts(b);
}
else{
System.out.println("你好!你购买的coffee是:");
System.out.println(b.getDescription());
System.out.println("总共是:" + b.cost());
}