java自动售货机饮料
时间: 2024-01-12 11:22:07 浏览: 149
简单的饮料售货机,java
5星 · 资源好评率100%
以下是一个简单的Java自动售货机饮料的示例:
```java
class Drink {
String name;
String taste;
public void info() {
System.out.println("当前购买的是:" + name + ", 口味是:" + taste);
}
}
public class VendingMachine {
public static void main(String[] args) {
Drink coke = new Drink();
coke.name = "可乐";
coke.taste = "甜";
coke.info(); // 输出:当前购买的是:可乐, 口味是:甜
Drink tea = new Drink();
tea.name = "茶";
tea.taste = "清淡";
tea.info(); // 输出:当前购买的是:茶, 口味是:清淡
}
}
```
阅读全文