作业


public class Account {
protected int id;// 账号
protected double  balance;//余额
protected   double annualInterestRate;//年利率
public Account(int id, double balance, double annualInterestRate) {
super();
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
//放回月利率
public  double getMonthlyInterest(){
return this.annualInterestRate/12;

}
//取款
public void withdraw (double amount){
if(this.balance>=amount){
this.balance=amount;
}else{
System.out.println("余额不足");
}

}
//存款
public void deposit (double amount){
this.balance+=amount;

}

}



public class TextAcoount {
public static void main(String[] args) {
Account s=new Account(1122,20000,0.045);
s.withdraw(30000);
System.out.println("当前余额"+s.getBalance());
s.withdraw(25000);
s.deposit(3000);
System.out.println("当前余额"+s.getBalance());
System.out.println("月利率"+s.getMonthlyInterest());

}


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值