2014-03-27 37 views
0

這是我創建的簡單投資類,它與一個測試器類一起創建。我不知道爲什麼測試人員給我一個錯誤找不到測試人員的符號。編譯器錯誤在投資類的測試器中找不到符號

public class Investments 
{ 
    // instance variables 
    private double moneyInvested; 
    private double investRate; 
    private int numOfYears; 

    double amount; 
    double rate; 
    int time; 

    public Investments(double moneyInvested, double investRate, int numOfYears) 
    { 
     this.amount = moneyInvested; 
     this.rate = investRate; 
     this.time = numOfYears; 
    } 

    public double ruleOf72() 
    { 
     return (72/this.rate/100); 
    } 

    public int simpleAnnual() 
    { 
     return Math.round(this.amount * Math.pow(1 + this.rate/100, this.time)); 
    } 

    public int compoundAnnual() 
    { 
     return Math.round(this.amount * Math.pow((1 + this.rate/100)^this.time)); 
    } 

} 

測試儀:

import java.util.Scanner; 

public class InvestmentsTester 
{ 
    public static void main(String[] args) 
    { 
    Scanner scanner = new Scanner(System.in); 
    System.out.println("How much money do you plan on investing?"); 
    double moneyInvested = scanner.nextDouble(); 

    System.out.println("How many years do you plan to invest this money?"); 
    int numOfYears = scanner.nextInt(); 

    System.out.println("At what percent rate would you like to invest?"); 
    double investRate = scanner.nextDouble(); 

    System.out.println("At a " + investRate + "% annual interest rate it would take you" + ruleOf72 + "years for your investments to double"); 
    System.out.println("Your simple annual interest after " + numOfYears + "years, with a initial investment of" + moneyInvested + "at" + investRate + "% will be worth:" + simpleAnnual); 
    System.out.println("Your compound annual interest after " + numOfYears + "years, with a initial investment of" + moneyInvested + "at" + investRate + "% will be worth:" + compoundAnnual); 
    } 

} 
+0

在main方法,其中'ruleOf72'聲明?你應該仔細研究'找不到符號'的含義。 –

回答

0

ruleOf72()simpleAnnual()compoundAnnual()Investments方法,你不能叫他們在你的主要方法變量。 你應該寫測試儀是這樣的:

public class InvestmentsTester 
{ 
    public static void main(String[] args) 
    { 
     Scanner scanner = new Scanner(System.in); 
     System.out.println("How much money do you plan on investing?"); 
     double moneyInvested = scanner.nextDouble(); 

     System.out.println("How many years do you plan to invest this money?"); 
     int numOfYears = scanner.nextInt(); 

     System.out.println("At what percent rate would you like to invest?"); 
     double investRate = scanner.nextDouble(); 

     Investments inverstment = new Investments(moneyInvested , numOfYears , investRate); //You should new an Investments object. Import Investments. 
     System.out.println("At a " + investRate + "% annual interest rate it would take you" + inverstment.ruleOf72() + "years for your investments to double"); //call ruleOf72() 
     System.out.println("Your simple annual interest after " + numOfYears + "years, with a initial investment of" + moneyInvested + "at" + investRate + "% will be worth:" + inverstment.simpleAnnual()); 
     System.out.println("Your compound annual interest after " + numOfYears + "years, with a initial investment of" + moneyInvested + "at" + investRate + "% will be worth:" + inverstment.compoundAnnual()); 
    } 

} 
0

你必須創建對象的投資,然後從它的對象調用ruleOf72。

例:

Investments i = new Investments(moneyInvested, investRate, numOfYears); 

然後調用 i.ruleOf72()