找不到符号 - 方法:变量(双)

时间:2017-03-31 06:41:26

标签: java variables methods cannot-find-symbol

我的程序还没有接近完成,但我被卡住了,因为编译器给了我一个错误信息"找不到符号 - 方法年(双)"在depreciatonTable方法中变量years。

- 我确信这是非常明显的,但我似乎无法弄清楚为什么编译器会出现错误。

import java.util.Scanner;
public class Problem1
{
public static void main(String args[])
{
    double AcquisVal, SalvageVal, years;
    Scanner scan = new Scanner(System.in);
    Problem1 val = new Problem1(); 

    System.out.println("Enter the Acquisition Value: ")  ;

    AcquisVal = scan.nextDouble();

    System.out.println("Enter the Salvage Value: ");

    SalvageVal = scan.nextDouble();

    System.out.println("Enter the years of useful life(in whole years): ");

    years = scan.nextDouble();

    if (AcquisVal < 0)
    {
        System.out.println("Acquisition value cannot be negative"); 
    }
    else if (years < 1){
        System.out.println("Years of useful life must be greater than zero");
    }
    else if (SalvageVal < 0){
        System.out.println("Salvage value cannot be negative");
    }
    else 
        val.depreciationtable(AcquisVal, SalvageVal, years);
}

public double depreciationtable(double years, double AcquisVal, double SalvageVal)
{
    double depreciation, fraction, annDepreciation, AccDepreciation, BookValue;

    while (years > 0)
    {
        fraction = years / (years (years + 1)/ 2);
        years--; 
    }
    depreciation = (AcquisVal - SalvageVal) * fraction;
    return depreciation;
}
}

1 个答案:

答案 0 :(得分:0)

中的逻辑存在问题

fraction = years / (years (years + 1)/ 2)years (years + 1)部分在逻辑上是错误的。

另外,请查看Java Naming conventions以使用正确的变量/方法名称。