admin管理员组文章数量:1647982
(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());
}
}
本文标签: Account
版权声明:本文标题:(Account类)设计一个名为Account的类 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1729495730a1202886.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论