无法找到符号错误不断弹出

时间:2016-08-04 05:30:33

标签: java

我对java很陌生,但我正在编写一个可以进行基本单位转换的程序。以下是我到目前为止的情况:

class Assignment8
{
public static void main(String[]args)
{
    System.out.println( "1. US Measurment to Metric" + "\n" + "2. Metric to US Measurement" );
    int us_or_metric = Input.getInt ( "Please enter the desired convertion" );
    switch ( us_or_metric )
    {
        case 1:
            System.out.println( "\n" + "1. Pound to Kilogram" + "\n" + "2. Ounce to Gram" + "\n" + "3. Foot to Meter" + "\n" + "4. Mile to Kilometer" );
            int us_conversions = Input.getInt( "Please enter the desired convertion" );
            switch ( us_conversions )
            {
                case 1:
                    double a = Input.getDouble( "Please enter amount to be converted" );
                    double b = 0.4536D;
                    System.out.println( a + "pound(s) is" + pound( a,b ) + "kilogram(s)" );
                    break;
                case 2:
                    double c = Input.getDouble ( "Please enter amount to be converted" );
                    double d = 28.5D;
                    System.out.println( c + "ounce(s) is" + ounce( c,d ) + "gram(s)" );
                    break;
                case 3:
                    double e = Input.getDouble ( "Please enter amount to be converted" );
                    double f = 0.3048D;
                    System.out.println( e + "feet is" + foot( e,f ) + "meter(s)" );
                    break;
                case 4:
                    double g = Input.getDouble ( "Please enter amount to be converted" );
                    double h = 1.61D;
                    System.out.println( g + "mile(s) is" + mile( g,h ) + "kilometer(s)" );
                    break;
            }
            break;
        case 2:
            System.out.println( "\n" + "1. Kilogram to Pound" + "\n" + "2. Gram to Ounce" + "\n" + "3. Meter to Foot" + "\n" + "4. Kilometer to Mile" );
            int metric_conversions = Input.getInt ( "Please enter the desired convertion" );
            switch ( us_conversions )
            {
                case 1:
                    double i = Input.getDouble( "Please enter amount to be converted" );
                    double j = 2.2046D;
                    System.out.println( i + "kilogram(s) is" + kilogram( i,j ) + "pound(s)" );
                    break;
                case 2:
                    double k = Input.getDouble ( "Please enter amount to be converted" );
                    double l = 0.0352D;
                    System.out.println( k + "gram(s) is" + gram( k,l ) + "ounce(s)" );
                    break;
                case 3:
                    double m = Input.getDouble ( "Please enter amount to be converted" );
                    double n = 3.2808D;
                    System.out.println( m + "meter(s) is" + meter( m,n ) + "feet" );
                    break;
                case 4:
                    double o = Input.getDouble ( "Please enter amount to be converted" );
                    double p = 0.6213D;
                    System.out.println( o + "kilometer(s) is" + kilometer( o,p ) + "mile(s)" );
                    break;
            }
            break;
    }
}

public static double pound( double a , double b )
{
    return a * b;
}


public static double ounce( double c , double d )
{
    return c * d;
}   

public static double foot( double e, double f )
{
    return e * f;
}

public static double mile( double g , double h )
{
    return g * h;
}
public static double kilogram( double i , double j )
{
    return i * j;
}
public static double gram( double k , double l )
{
    return k * l;
}
public static double meter( double m , double n )
{
    return m * n;
}
public static double kilometer( double o , double p )
{
    return o * p;
}

}

当我去编译它时,我得到了无法找到符号的错误。我在这里看过这个页面 What does a "Cannot find symbol" compilation error mean? 但我无法确定我的问题。有人可以帮我找到错误吗?对不起,如果它是明显的东西,但我仍然是编码菜鸟。 我得到了编译和运行的程序,但只在特定的位置,我的桌面上标有java的文件夹。关于为什么会发生这种情况的任何想法?

Compilation errors

Compilation error   time: 0 memory: 0 signal:0
Main.java:13: error: cannot find symbol
    int us_or_metric = Input.getInt ( "Please enter the desired convertion" );
                       ^
  symbol:   variable Input
  location: class Assignment8
Main.java:18: error: cannot find symbol
            int us_conversions = Input.getInt( "Please enter the desired convertion" );
                                 ^
  symbol:   variable Input
  location: class Assignment8
Main.java:22: error: cannot find symbol
                    double a = Input.getDouble( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:27: error: cannot find symbol
                    double c = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:32: error: cannot find symbol
                    double e = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:37: error: cannot find symbol
                    double g = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:45: error: cannot find symbol
            int metric_conversions = Input.getInt ( "Please enter the desired convertion" );
                                     ^
  symbol:   variable Input
  location: class Assignment8
Main.java:49: error: cannot find symbol
                    double i = Input.getDouble( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:54: error: cannot find symbol
                    double k = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:59: error: cannot find symbol
                    double m = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
Main.java:64: error: cannot find symbol
                    double o = Input.getDouble ( "Please enter amount to be converted" );
                               ^
  symbol:   variable Input
  location: class Assignment8
11 errors

1 个答案:

答案 0 :(得分:0)

错误消息说了什么?

当它超出范围时,您正尝试使用us_conversions。 (这应该重命名为imperial_conversions

case 2:
            System.out.println( "\n" + "1. Kilogram to Pound" + "\n" + "2. Gram to Ounce" + "\n" + "3. Meter to Foot" + "\n" + "4. Kilometer to Mile" );
            int metric_conversions = Input.getInt ( "Please enter the desired convertion" );
            switch ( us_conversions ) // <-- Here is your problem, change to metric_conversions
            {
                case 1: