2014-02-13 41 views
-1
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; 
    } 
} 

这是我尝试不同的事情,但它仍然无法正常工作帐户级示值误差

+0

你的'AccountDriver'类别在哪里 –

+0

它在顶部 – user3304653

+3

使用IDE。它会在您写作时捕获这些类型的错误,并为您提供错误原因。 – abhi120

回答

4

你的方法getMontlyInterestRate错误

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method getMontlyInterest(double) in the type Account is not applicable for the arguments()

at AccountDriver.main(AccountDriver.java:21)

需要一个参数(月息)率,你没有给你的主要任何东西。

System.out.println("The 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; 
    } 
+0

like that double x = Account.getMontlyInterestRate(montlyInterestRate); – user3304653

+1

like this System.out.println(“The montly interest is:”+ number2.getMontlyInterest(40.0)); –

+0

为什么我需要放40.0? – user3304653