(Account类)设计一个名为Account的类

(Account类)设计一个名为Account的类,其中包含:

私有int数据字段id。账户(默认值0)。

一个名为balancefort的私有双数据字段。

一个名为annualInteresrent interest rate(默认值为o)的双数据字段。

假设所有accots都有这个帐户(默认值为0)。“利率是一样的。

名为dateCreated的Date数据字段,存储创建帐户时的日期。

创建默认帐户的无参数构造函数。

一个构造函数,它使用指定的id和初始余额创建一个帐户。用于id、balance和annualInterestRate的getter和setter方法。dateCreated的访问器方法。

一个名为getMonthlyInterestRate()的方法,返回月利息。

从帐户中提取指定金额的名为withdraw()的方法。

从帐户中存取指定金额的名为deposit()的方法

一个存款的方法,它将一定数额的存款存入帐户。实现该类。(提示。按月计息的方法是按月还利息,而不是按月还利息。每月利息是余额*每月利息/12。)

编写一个测试程序,创建一个帐号,帐号ID为1222, balanceof: 200,年利率为4.5%。使用 withdraw提取$2,500,使用deposit存储$3000,打印余额,每月利息,以及创建该帐户的日期。

package jing.able;
import java.util.Date;

/**
 * @author: panjing
 * @describe:   设计一个类
 * @date: 2019/5/9
 * @time: 17:53
 */

public class DesignClassd {
    public static void main(String[] args) {
        Account account = new Account(1122,20000);
        account.setAnnualInterestRate(0.045);
        account.withDraw(2500);
        account.deposit(3000);
        account.getAccountInfor();
    }
}
class Account{
    private int id;
    private double balance;  //初始余额
    private double annualInterestRate;   //存储年利率
    private Date dateCreated; //存储账户的开户日期

    public Account(){} //构建Account的无参构造方法

    public Account(int id,double balance){
        this.id = id;
        this.balance = balance;
    }

    public double getBalance() {
        return this.balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getAnnualInterestRate() {
        return this.annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }

    //返回月利息
    public double getMonthlyInterestRate(){
        return (this.annualInterestRate/12) * this.balance;
    }

    //从账户提取特定数额
    public  double withDraw(double money){
        this.balance = balance - money;
        return this.balance;
    }
    //从账户存取特定数额
    public double deposit(double money){
        this.balance = balance + money;
        return this.balance;
    }

    public void getAccountInfor(){
        System.out.println("余额为" + this.balance +"美元"+ "\n" +
                "月利息为" + getMonthlyInterestRate()+"\n"+
                "开户日期为"+getDateCreated());
    }
}

 

  • 21
    点赞
  • 79
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值