面向对象(用程序写出自动售货机)
emmm开头第一步,日后还要多加学习
public class VendingMachine {
int price=80;
int balance;
int total;
void showPrompt(){
System.out.println("Welcome");
}
void insertmoney(int amount){
balance=balance+amount;
}
void showBalance(){
System.out.println(balance);
}
void getFood(){
if (balance>=price){
System.out.println("Here you are");
balance=balance-price;
total=balance+price;
}
}
public static void main(String[] args) {
VendingMachine vm=new VendingMachine();
vm.showBalance();
vm.showPrompt();
vm.insertmoney(100);
vm.getFood();
vm.showBalance();
VendingMachine vm1=new VendingMachine();
vm1.insertmoney(200);
vm1.showBalance();
}
}