package banking1;
public class Account {
private double balance;//账号余额
public Account(double init_balance){
balance=init_balance;
}
public double getBalance(){
return balance;
}
public void despoit(double amt){
balance+=amt;
}
public void withdraw(double amt){
if(balance>amt){
balance-=amt;
}else{
System.out.println("账户余额不足");
}
}
}
package testbanking1;
import banking1.Account;
public class testbanking1 {
public static void main(String[] args){
Account account;
account =new Account(500.00);
System.out.println("creating an account with a 500.00 balance ");
account.withdraw(150.00);//调用withdraw
System.out.println("withdraw 150.00");
account.despoit(22.50);
System.out.println("despoit 150.00");
account.withdraw(47.62);
System.out.println("withdraw 47.62");
System.out.println("the account has a balance of :"+account.getBalance());
}
}