Java 获取:找不到符号错误

Java 获取:找不到符号错误,java,variables,symbols,Java,Variables,Symbols,在代码的底部,我尝试将输入传递给一个名为ISPCharge的新类,但我一直遇到“找不到符号”错误。为什么会这样?(我是初学者。) 我正在尝试传递packageCode和Hours变量。此代码要求使用readHours和readPackage变量。有什么建议吗?该类已与其应连接的类位于同一文件夹中 import java.util.Scanner; public class ISPBilling { static char packageCode; static d

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

我正在尝试传递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;

    };
}

有关格式,请参见样式公会 */ 公共课收费 { //描述此电荷的变量。 私有字符包码; 私人双小时

//在这里声明您的常量。它们应该使用私有 //可见性修改器

  /**************************************************** 
* 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;


 };
/*********************************************************************
*构造函数设置包和小时属性。
*@param pkg包A、B或C的代码
*@param hours本月的小时数
*/
公共双倍收费(双倍小时,字符包代码)
{
返程时间;
}
/************************************************
*计算费用将决定申请哪种套餐
*并将返回正确的成本。
*
*@退还本月的费用。
*/
公共双成本{
如果(packageCode='A'&&hours<10){
返回calcA();
}否则如果(packageCode='A'&&hours>10){
返回calcA()+(小时-20)*2;
}否则如果(包装代码=='B'&小时数<20){
返回calcB();
}否则如果(packageCode='B'&&hours>20){
返回时间(小时-20)+calcB();
}else if(packageCode=='C'){
calcC();
}否则
返回0;
返程时间;
};
/************************************************
*calcA计算A包的费用
*
*剩下的就留给你填写了。。。。
*/
公共双卡(){
回报率9.95;
};
//把calcA方法放在这里
/************************************************
*calcB计算B包的费用
*
*剩下的就留给你填写了。。。。
*/
公共双calcB(){
回报率13.95;
};
//把calcB方法放在这里
/************************************************
*calcC计算包裹C的费用
*
*剩下的就留给你填写了。。。。
*/
公共双calcC(){
回报率19.95;
};
//将calcC方法放在这里
/**calcTax计算通过的费用的税款
*
*剩下的就留给你填写了。。。。
*/
公共双calcTax(){
返回calcCost()/5;
};

}

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

import your.package.ISPCharge ;
并使用以下定义更改构造函数

因为
public double ISPCharge(双倍小时,char packageCode)
是有效的方法,但不是构造函数,因为构造函数不能有返回值

public  ISPCharge( double hours,char packageCode)
{

  .......

 }

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

public ISPCharge( double hours,char packageCode)
{

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

}

它在我的文件中,只是不在本例中。它们在一起。这两个类位于同一个包下。请分享其他类别的代码。
public ISPCharge( double hours,char packageCode)
{

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

}