编译器错误无法在测试人员中找到投资类别的符号

时间:2014-03-27 01:02:52

标签: java

这是我与测试人员课程一起创建的简单投资课程。我不知道为什么测试人员给我一个错误,找不到测试人员的符号。

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);
   }

}

2 个答案:

答案 0 :(得分: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());
     }

 }

答案 1 :(得分:0)

您必须创建Investments对象,然后从它的对象中调用ruleOf72。

前:

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

然后打电话     i.ruleOf72()