Java帐户类程序

Java帐户类程序,java,Java,我已经一遍又一遍地写了这个程序,有人能告诉我我遗漏了什么吗?看起来这是一个我没有抓住的小错误 以下是我试图实现的目标: 设计名为Account的类,该类包含: 帐户的名为id的私有int数据字段(默认值为0) 帐户名为余额的专用双精度数据字段(默认值为0) 名为annualInterestate的专用双数据字段,用于存储 当前利率(默认为0)。假设所有帐户都具有相同的 利率 名为dateCreated的专用日期数据字段,用于存储创建帐户的日期。创建默认帐户的无参数构造函数 创建帐户的构造函数

我已经一遍又一遍地写了这个程序,有人能告诉我我遗漏了什么吗?看起来这是一个我没有抓住的小错误

以下是我试图实现的目标:

设计名为Account的类,该类包含:

  • 帐户的名为id的私有int数据字段(默认值为0)
  • 帐户名为余额的专用双精度数据字段(默认值为0)
  • 名为annualInterestate的专用双数据字段,用于存储 当前利率(默认为0)。假设所有帐户都具有相同的 利率
  • 名为dateCreated的专用日期数据字段,用于存储创建帐户的日期。创建默认帐户的无参数构造函数
  • 创建帐户的构造函数 具有特定id和初始余额
  • id、balance和AnnualInterestate的访问器和变异器方法
  • dateCreated的访问器方法
  • 一个名为getMonthlyInterestate()的方法,返回月利率
  • 从帐户中提取指定金额的名为draw的方法将指定金额存入帐户的名为deposit的方法
  • 编写一个测试程序 创建帐户ID为1122的帐户对象,余额为 20000美元,年利率4.5%。使用提取方法 要提取2500美元,请使用存款方法存款3000美元,然后 打印余额、月利息和支付日期 帐户已创建
以下是我目前掌握的情况:

import java.util.Date;

public class Assign22 {

public static void main(String[] args) {
    // TODO Auto-generated method stub

Account account1 = new Account(1122, 20000, .045);
account1.withdraw(2500);
account1.deposit(3000);
System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
System.out.println("Account ID:" + account1.id);
System.out.println("Balance:" + account1.getBalance());
System.out.println("Interest Rate:" + account1.getAnnualInterestRate());
System.out.println("Balance after withdraw of 2500:" +       account1.getAnnualInterestRate());
System.out.println("Balance after deposit of 3000:" + account1.getAnnualInterestRate());
System.out.println("Monthly Interest:" + account1.id);

System.out.println("Process completed.");
}

class Account {
//define variables
private int id;
private double balance; // balance for account
private double annualInterestRate; //stores the current interest rate
private Date dateCreated; //stores the date account created

//no arg construtor
Account () {
    id = 0;
    balance = 0.0;
    annualInterestRate = 0.0;
}
//constructor with specific id and initial balance
Account(int newId, double newBalance) {
    id = newId;
    balance = newBalance;
}
Account(int newId, double newBalance, double newAnnualInterestRate) {
    id = newId;
    balance = newBalance;
    annualInterestRate = newAnnualInterestRate;
}
//accessor/mutator methods for id, balance, and annualInterestRate
public int getId() {
    return id;
}
public double getBalance() {
    return balance;
}
public double getAnnualInterestRate() {
    return annualInterestRate;
}
public void setId(int newId) {
    id = newId;
}
public void setBalance(double newBalance) {
    balance = newBalance;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
    annualInterestRate = newAnnualInterestRate;
}
//accessor method for dateCreated
public void setDateCreated(Date newDateCreated) {
    dateCreated = newDateCreated;
}
//define method getMonthlyInterestRate
double getMonthlyInterestRate() {
    return annualInterestRate/12;
}
//define method withdraw
double withdraw(double amount) {
    return balance -= amount;
}   
//define method deposit
double deposit(double amount) {
    return balance += amount;   
}
}

}
这是我收到的错误:不确定我错过了什么:

import java.util.Date;

public class Assign22 {

public static void main(String[] args) {
    // TODO Auto-generated method stub

Account account1 = new Account(1122, 20000, .045);
account1.withdraw(2500);
account1.deposit(3000);
System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
System.out.println("Account ID:" + account1.id);
System.out.println("Balance:" + account1.getBalance());
System.out.println("Interest Rate:" + account1.getAnnualInterestRate());
System.out.println("Balance after withdraw of 2500:" +       account1.getAnnualInterestRate());
System.out.println("Balance after deposit of 3000:" + account1.getAnnualInterestRate());
System.out.println("Monthly Interest:" + account1.id);

System.out.println("Process completed.");
}

class Account {
//define variables
private int id;
private double balance; // balance for account
private double annualInterestRate; //stores the current interest rate
private Date dateCreated; //stores the date account created

//no arg construtor
Account () {
    id = 0;
    balance = 0.0;
    annualInterestRate = 0.0;
}
//constructor with specific id and initial balance
Account(int newId, double newBalance) {
    id = newId;
    balance = newBalance;
}
Account(int newId, double newBalance, double newAnnualInterestRate) {
    id = newId;
    balance = newBalance;
    annualInterestRate = newAnnualInterestRate;
}
//accessor/mutator methods for id, balance, and annualInterestRate
public int getId() {
    return id;
}
public double getBalance() {
    return balance;
}
public double getAnnualInterestRate() {
    return annualInterestRate;
}
public void setId(int newId) {
    id = newId;
}
public void setBalance(double newBalance) {
    balance = newBalance;
}
public void setAnnualInterestRate(double newAnnualInterestRate) {
    annualInterestRate = newAnnualInterestRate;
}
//accessor method for dateCreated
public void setDateCreated(Date newDateCreated) {
    dateCreated = newDateCreated;
}
//define method getMonthlyInterestRate
double getMonthlyInterestRate() {
    return annualInterestRate/12;
}
//define method withdraw
double withdraw(double amount) {
    return balance -= amount;
}   
//define method deposit
double deposit(double amount) {
    return balance += amount;   
}
}

}

“令牌“日期”上的语法错误(在此令牌日期之后出现)无法解析为Assign22.main(Assign22.java:12)处的变量”

您不能将变量声明作为连接表达式的一部分

System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
分开

java.util.Date dateCreated = new java.util.Date()
System.out.println("Date Created:" + dateCreated);

不能将变量声明作为
String
串联表达式的一部分

System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
分开

java.util.Date dateCreated = new java.util.Date()
System.out.println("Date Created:" + dateCreated);

不能将变量声明作为
String
串联表达式的一部分

System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
分开

java.util.Date dateCreated = new java.util.Date()
System.out.println("Date Created:" + dateCreated);

不能将变量声明作为
String
串联表达式的一部分

System.out.println("Date Created:" + java.util.Date dateCreated = new java.util.Date());
分开

java.util.Date dateCreated = new java.util.Date()
System.out.println("Date Created:" + dateCreated);