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

2024-11-04 12:20:04
推荐回答(4个)
回答1:

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:

你这个编程的难度不是一般的高啊,还是全英文的题目,感觉有点发酥

回答3:

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:

so easy!