有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

account Java简单会计程序

import java.util.Date;
public class Exercise08_07 {
public static void main (String[] args) {
Account account = new Account(1122, 20000);
account.setAnnualInterestRate(4.5);

account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " +
  account.getMonthlyInterest());
  System.out.println("This account was created at " +
  account.getDateCreated());
  }
}

class Account 
{
//define variables 
private int id;
private double balance;
private double annualInterestRate;
private Date dateCreated;

//a no-arg constructor that creates a default account.

public Account()

{
id = 0;
balance = 0.0;
annualInterestRate = 0.0;
}
 //constructor creates an account with the specified id and initial balance
  public Account(int id, double balance){
  this.id = id;
  this.balance = balance;

}
  public Account (int newId, double newBalance, double newAnnualInterestRate)
  { 
      id = newId;
      balance = newBalance;
      annualInterestRate = newAnnualInterestRate;

  }
  //accessor and 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 id){
      this.id = id;
  }
  public void setBalance(double balance){
      this.balance=balance;
  }
  public void setAnnualInterestRate(double annualInteresteRate){
      this.annualInterestRate = annualInterestRate;
  }
      //accessor method for dateCreated
  public void setDateCreated(Date newDateCreated){
      dateCreated = newDateCreated;
  }
     //method named getMonthlyInterestRate()that returns the monthly interest rate.
  double getMonthlyInterest(){
      return annualInterestRate/12;      
  }
  Date getDateCreated(){
      return dateCreated;
  }
  //method named withdraw that withdraws a specified amount from the account.
  double withdraw (double amount){
      return balance -= amount;
  }
  //method named deposit that deposits a specified amount to the account
  double deposit (double amount){
      return balance += amount;
  }
  }

这是我第一次在这里发帖,不确定如何在这里发帖,netbean没有显示任何错误,但输出不正确,我不确定代码哪里出错了,我是Java新手,请帮助我解决这个问题,谢谢! 输出:

balance is 20500.0

monthly interest is 0.0

this account was created at null

I am not sure why the output is incorrect, can anyone help please?

共 (0) 个答案