Java模板设计模式_抽象类模拟咖啡机的工作

 1 import java.util.Scanner;
 2 class Test {
 3 
 4 
 5     public static void main(String[] args) {
 6         coffee per = new coffee();
 7         per.shaoshui();
 8         per.receipt();
 9         per.custom();
10         per.jiaoban();
11         per.dicha();
12     }
13 }
14 
15     abstract  class beverage{
16        private  void shaoshui(){
17             System.out.println("烧开水");
18     }
19         abstract  void receipt();
20       private  void jiaoban(){
21             System.out.println("搅拌饮料");
22         }
23 
24         void dicha(){
25             System.out.println("给大佬递饮料");
26         }
27     }
28     class coffee extends beverage{
29           void shaoshui(){
30             System.out.println("烧开水");
31 
32         }
33          void receipt() {
34              System.out.println("加一包秘制咖啡粉");
35          }
36 
37          public static boolean custom(){
38 
39             System.out.println("需要加牛奶吗?");
40             Scanner scanner=new Scanner(System.in);
41             String str=scanner.nextLine();
42             if(str.equalsIgnoreCase("y")){
43                 System.out.println("加一包牛奶");
44                 return true;
45             }
46             else if (str.equalsIgnoreCase("n")){
47                 System.out.println("客户不需要加牛奶");
48                 return false;
49             }
50             else{
51                 System.out.println("非法输入");
52                 return false;
53             }
54 
55         }
56         void jiaoban(){
57             System.out.println("搅拌饮料");
58         }
59         void dicha(){
60             System.out.println("给大佬递咖啡");
61         }
62     }

运行结果:

 

转载于:https://www.cnblogs.com/hetaoyuan/p/10566443.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值