Java作业紧急求助
答案:1 悬赏:50 手机版
解决时间 2021-01-19 15:11
- 提问者网友:缘字诀
- 2021-01-19 01:47
Java作业紧急求助
最佳答案
- 五星知识达人网友:山有枢
- 2021-01-19 02:08
import java.util.Date;
public class Account
{
private int id;
private double balance=0;
private double annualInterestRate=0;
private Date dataCreated;
public Account()
{
super();
this.dataCreated=new Date();
}
public Account(int id, double balance)
{
super();
this.id = id;
this.balance = balance;
this.dataCreated=new Date();
}
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 Date getDataCreated()
{
return dataCreated;
}
public void setAnnualInterestRate(double annualInterestRate)
{
this.annualInterestRate = annualInterestRate;
}
public double getMinthlyInterestRate() throws Exception
{
if(this.annualInterestRate==0)
{
throw new Exception("还没设置利息呢");
}else {
return annualInterestRate/12;
}
}
public void withDraw(double MoneyNum) throws Exception
{
if(MoneyNum>this.balance)
{
throw new Exception("没那么多钱");
}else
{
this.balance-=MoneyNum;
}
}
public void deposit(double MoneyNum)
{
this.balance+=MoneyNum;
}
public static void main(String[] args) throws Exception
{
Account myAccount=new Account(1122, 20000);
myAccount.setAnnualInterestRate(4.5/100);
myAccount.withDraw(2500);
myAccount.deposit(3000);
System.out.println("余额:"+myAccount.getBalance());
System.out.println("月利息:"+myAccount.getMinthlyInterestRate());
System.out.println("开户日期:"+myAccount.getDataCreated());
}
}
public class Account
{
private int id;
private double balance=0;
private double annualInterestRate=0;
private Date dataCreated;
public Account()
{
super();
this.dataCreated=new Date();
}
public Account(int id, double balance)
{
super();
this.id = id;
this.balance = balance;
this.dataCreated=new Date();
}
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 Date getDataCreated()
{
return dataCreated;
}
public void setAnnualInterestRate(double annualInterestRate)
{
this.annualInterestRate = annualInterestRate;
}
public double getMinthlyInterestRate() throws Exception
{
if(this.annualInterestRate==0)
{
throw new Exception("还没设置利息呢");
}else {
return annualInterestRate/12;
}
}
public void withDraw(double MoneyNum) throws Exception
{
if(MoneyNum>this.balance)
{
throw new Exception("没那么多钱");
}else
{
this.balance-=MoneyNum;
}
}
public void deposit(double MoneyNum)
{
this.balance+=MoneyNum;
}
public static void main(String[] args) throws Exception
{
Account myAccount=new Account(1122, 20000);
myAccount.setAnnualInterestRate(4.5/100);
myAccount.withDraw(2500);
myAccount.deposit(3000);
System.out.println("余额:"+myAccount.getBalance());
System.out.println("月利息:"+myAccount.getMinthlyInterestRate());
System.out.println("开户日期:"+myAccount.getDataCreated());
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯