帐户类显示错误

时间:2014-02-13 06:43:45

标签: java class

public class Driver {
    public static void main(String[] args) {

    //ID, Balance, Annual Interest Rate 
        Account number1 = new Account();
        Account number2 = new Account(1122,20000.00,0.045);     


       //Default account
        System.out.println("The Account ID is:  " + number1.getId());
        System.out.println("The Account Balance is: "+ number1.getBalance());
        //System.out.println("The Account Balance is: "+ number1.getMontlyInterest());
        System.out.println("");

        //Ask to withdraw 2500
        System.out.println("The Account ID is:  " + number2.getId());
        number2.withdraw(2500.00);
        number2.deposit(3000.00);
        System.out.println("Account Balance is "+ number2.getBalance());
        System.out.println("The montly interest is : "+ number2.getMontlyInterest());
        System.out.println("");

    }
}


public class Account {

    private int id=0;
    private double balance=0;
    private double annualInterestRate=0;


    public Account(int id, double balance, double annualInterestRate) {
        this.setId(id);
        this.setBalance(balance);
        this.setAnnualInterestRate(annualInterestRate);

    }

    public Account() {

    }

    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 double getMontlyInterest() {
    //Given Formula 
        double MontlyInterest = this.balance * getMontlyInterestRate();
        return MontlyInterest;
    }


    public double getMontlyInterestRate(double montlyInterestRate){
    //Given Formula
        montlyInterestRate= this.annualInterestRate/12;
        return montlyInterestRate;

    }


    double withdraw(double amount){

    return balance -=amount;
    }


    double deposit(double amount){

    return balance += amount;   
    }
}

这是错误

  

线程“main”中的异常java.lang.Error:未解决的编译问题:类型getMontlyInterest(double)中的方法Account不适用于arguments ()

     

AccountDriver.main(AccountDriver.java:21)

我尝试不同的东西,但它仍然不起作用

1 个答案:

答案 0 :(得分:4)

您的方法getMontlyInterestRate需要一个参数(每月利息)费率,您没有在主要费用中提供任何费用。

  

System.out.println(“montly interest is:”+   number2.getMontlyInterest());

事实上你不需要你的论证double montlyInterestRate,因为你在方法中分配它......只需删除它:

public double getMontlyInterestRate(/*montlyInterestRate*/)
{
    double montlyInterestRate= this.annualInterestRate/12;
    return montlyInterestRate;
}

并且方法getMontlyInterest中的内容相同:

public double getMontlyInterest(/*double montlyInterest*/) {
    //Given Formula 
        double montlyInterest = this.balance * getMontlyInterestRate();
        return montlyInterest;
    }