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);
}
}
在main方法,其中'ruleOf72'聲明?你應該仔細研究'找不到符號'的含義。 –