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

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.

第1个回答  推荐于2017-10-24
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());
}

}
不谢!分数拿来~本回答被提问者采纳
第2个回答  2017-10-24
你这个编程的难度不是一般的高啊,还是全英文的题目,感觉有点发酥
第3个回答  2012-11-06
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
第4个回答  2012-11-06
so easy!

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网