获取:找不到符号错误

时间:2013-11-07 03:07:34

标签: java variables symbols

在代码的底部,我尝试将输入传递给一个名为ISPCharge.BUT的新类。我不断收到“找不到符号”错误。为什么会这样? (我是初学者。)

我正在尝试传递packageCode和Hours变量。使用readHours和readPackage变量是此代码的要求。有什么建议?此类已与它应连接的类位于同一文件夹中。

import java.util.Scanner;

public class ISPBilling {


      static char packageCode;

      static double hours;

      public static void main (String[] Args){


    Scanner keyboard  = new Scanner(System.in);

    System.out.println("Enter the package code (A, B, or C): ");
    packageCode = keyboard.next(".").charAt(0);

     readPackage(packageCode);

  System.out.println("Enter the number of hours used: ");
      hours = keyboard.nextDouble();
      readHours(hours);

      };

      public static double readHours(double hours){

       if(hours >= 0){

        return hours;

      }else 

           System.out.println("Your entry, " + hours + " is invalid.");
           System.out.println();

           return hours = 0;
       };    

    public static char readPackage(char packageCode){

     if (packageCode == 'a' || packageCode == 'A'){

        packageCode = 'A';

        return 'A';

    }else if (packageCode == 'b' || packageCode == 'B'){

        packageCode = 'B';

        return 'B';

      }else if(packageCode == 'c' || packageCode == 'C'){

        packageCode = 'C';

        return 'C';

      }else{  


         System.out.println("Your entry, " + packageCode + " is invalid.");
           System.out.println();


       packageCode = 'A';

       }


       return packageCode;

     };


    public double classcharge(){

    readPackage(packageCode);

    readHours(hours);

    ISPCharge ISPCharger = new ISPCharge(hours, packageCode); // THIS IS IT.

    return hours;

    };

}

/** put your documentation for this class here

请参阅Style Guild了解格式    * /    公共类ISPCharge     {    //描述此费用的变量。    private char packageCode;    私人双小时;

//在这里声明你的常量。他们应该使用私人    //可见性修饰符。

  /**************************************************** 
* The constructor sets the package and hours attributes.
* @param pkg The code for the package, A, B, or C
* @param hours The number of hours this month
*/
public double ISPCharge( double hours,char packageCode)
{

  return hours;

 }

/************************************************
* calc charge will decide which package to apply
* and will return the correct cost.
*
* @return The charges for this month.
*/
public double calcCost(){

if (packageCode == 'A' && hours < 10){

    return calcA();

}else if(packageCode == 'A' && hours > 10){

  return calcA() + (hours  - 20) * 2;

}else if(packageCode == 'B'&& hours  < 20){

  return calcB();

}else if(packageCode == 'B' && hours  > 20 ){

  return (hours  - 20) + calcB();

}else if (packageCode == 'C'){

  calcC();

}else 

 return 0;


 return hours;
};


/************************************************
* calcA calculates the charges for package A
*
* The rest is left for you to fill in....
*/
public double calcA(){

 return 9.95;

};
// put the calcA method here

/************************************************
* calcB calculates the charges for package B
*
* The rest is left for you to fill in....
*/
public double calcB(){

return  13.95;


};
// put the calcB method here


/************************************************
* calcC calculates the charges for package C
*
* The rest is left for you to fill in....
*/
public double calcC(){

return 19.95;

};


// put the calcC method here


/** calcTax calculates the tax on the passed charge
 *
 * The rest is left for you to fill in....
 */
 public double calcTax(){

 return calcCost() / 5;


 };

}

2 个答案:

答案 0 :(得分:0)

似乎类ISPCharge与提及的类不在同一个包中。因此,您需要导入类,如下所示。希望这能解决你的问题。

import your.package.ISPCharge ;

使用以下定义更改构造函数,

因为public double ISPCharge( double hours,char packageCode)是有效的方法而不是构造函数,因为构造函数不能具有返回值。

public  ISPCharge( double hours,char packageCode)
{

  .......

 }

答案 1 :(得分:0)

ISPCharge的构造函数不应该有返回类型,因为它的工作是设置对象,而不是返回值。删除单词double并设置私有变量,而不是返回值:

public ISPCharge( double hours,char packageCode)
{

    this.hours=hours;
    this.packageCode=packageCode;

}