java编写账户(余额,月利息,开户日期)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java编写账户(余额,月利息,开户日期)相关的知识,希望对你有一定的参考价值。
import java.util.Date;
public class TestAccount //测试类
{
public static void main(String[] args)
{
Account c1=new Account(1122,20000);
c1.setAnnualInterestRate(4.5/100);
c1.withDraw(2500);
c1.deposit(3000);
System.out.println("余额为"+c1.getBalance());
System.out.println("月利息为"+c1.getMonthlyInterest()+‘%‘);
System.out.println("开户日期是"+c1.getDateCreated().toString());
}
}
class Account //功能类
{
private int id;
private double balance;
private double annualInterestRate;
private Date dateCreated;
public Account()
{
dateCreated=new Date();
}
public Account(int x,double y)
{
id=x;
balance=y;
dateCreated=new Date();
}
public void setid(int x)
{
id=x;
}
public int getId()
{
return id;
}
public void setBalance(double x)
{
balance=x;
}
public double getBalance()
{
return balance;
}
public void setAnnualInterestRate(double x)
{
annualInterestRate=x;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public Date getDateCreated()
{
return dateCreated;
}
public double getMonthlyInterestRate()
{
return annualInterestRate/12;
}
public double getMonthlyInterest()
{
return getMonthlyInterestRate()*balance;
}
public void withDraw(double money)
{
if(balance>=money)
balance-=money;
}
public void deposit(double money)
{
balance+=money;
}
}
以上是关于java编写账户(余额,月利息,开户日期)的主要内容,如果未能解决你的问题,请参考以下文章
编写一个类似银行账户的程序,属性:账号 储户姓名 地址 存款余额 利率。方法:存款 取款查询余额计算利息