int id; double balance; //借款 public void withDrew(double money){ if (money>this.balance){ System.out.println("你没钱"); }else { this.balance-=money; showMoney(); } } //存款 public void deposit(double money){ this.balance+=money; showMoney(); } //显示余额 public void showMoney(){ System.out.println(this.id+":"+this.balance); }
public static void main(String[] args) { //创建俩个账户 Account account=new Account(); account.balance=900; account.id=666; Account account1=new Account(); account1.balance=100; account1.id=888; account.withDrew(800); account1.deposit(800); }