急急急!求java大神帮忙编写一个程序,谢谢啦

DesignaclassnamedAccountthatcontains:■Aprivateintdatafieldnamedidfortheaccount(defaul... Design a class named Account that contains:
■ A private int data field named id for the account (default 0).
■ A private double data field named balance for the account (default 0).
■ A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate.
■ A private Date data field named dateCreated that stores the date when the account was created.
■ A no-arg constructor that creates a default account.
■ A constructor that creates an account with the specified id and initial balance.
■ The accessor and mutator methods for id, balance, and annualInterestRate.
■ The accessor method for dateCreated.
■ A method named getMonthlyInterestRate() that returns the monthly interest rate.
■ A method named withdraw that withdraws a specified amount from the account.
■ A method named deposit that deposits a specified amount to the account.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when this account was created.
展开
 我来答
困境and变局
推荐于2017-10-24 · TA获得超过130个赞
知道答主
回答量:2
采纳率:0%
帮助的人:2.6万
展开全部
Class Account{
private int id;
private double balance;
private double annuallnterestRate;
private Date dateCreated;

public Account(){
this.id = 0;
this.balance = 0;
this.annuallnterestRate = 0;
this.dateCreated = new Date();
}

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

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

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

public double getBalance(){
return this.balance
}

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

public double getAnnuallnterestRate(){
return this.annuallnterestRate
}

public void setAnnuallnterestRate(double annuallnterestRate){
this.annuallnterestRate = annuallnterestRate
}

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

public double getMonthlyInterestRate(){
double monthlyInterest = java.lang.StrictMath.pow(this.annuallnterestRate,1.0/12)-1;
return monthlyInterest;
}

public String withdraw(double amount){
this.balance = this.balance-amount;
return "withdraw success";
}

public String deposit(double amount){
this.balance = this.balance+amount;
return "deposit success";
}

public static void main(String[] args){
Account account = new Account(1122,20000.00);
account.setAnnuallnterestRate(0.045);
account.withdraw(2500.00);
account.deposit(3000.00);
System.out.println(account.getBalance());
System.out.println(account.getMonthlyInterestRate());
System.out.println(account.getDateCreated());
}

}
不谢!分数拿来~
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
老戴在此564
2017-10-24 · TA获得超过2002个赞
知道大有可为答主
回答量:3874
采纳率:72%
帮助的人:455万
展开全部
你这个编程的难度不是一般的高啊,还是全英文的题目,感觉有点发酥
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
亡灵天使12608
2012-11-06
知道答主
回答量:13
采纳率:0%
帮助的人:21.4万
展开全部
Account.java 类
import java.util.Date;
public class Account {
int id;
double balance;
double annualInterestRate;
private Date dateCreated;
public Account(){
Date date=new Date();
dateCreated=date;
}
public Account(int id,double balance){
Date date=new Date();
dateCreated=date;
this.id=id;
this.balance=balance;
}
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 Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate(){
return annualInterestRate*balance;
}
public void withdraw(double money){
balance-=money;
}
public void deposit (double money){
balance+=money;
}
}
main.java 主程序
import java.util.Date;
public class main {
public static void main(String[] args) {
Account person=new Account(1122,20000d);
person.setAnnualInterestRate(0.045);
person.withdraw(2500d);
person.deposit(3000d);
System.out.println("the balance is "+person.getBalance()+"$");
System.out.println("the monthly interest is "+person.getMonthlyInterestRate()+"$");
System.out.println("the date when this account was created is "+person.getDateCreated().toLocaleString());;
}
}
运行结果:
the balance is 20500.0$
the monthly interest is 922.5$
the date when this account was created is 2012-11-6 16:54:23
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ljjtq
2012-11-06 · 超过17用户采纳过TA的回答
知道答主
回答量:94
采纳率:0%
帮助的人:47.3万
展开全部
so easy!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 3条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式