在代码的底部,我尝试将输入传递给一个名为 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;
};
}
/** put your documentation for this class here
格式见 Style Guild */ public class ISPCharge { // 描述此费用的变量。私有字符包代码;私人双小时;
// 在这里声明你的常量。他们应该使用私有 // 可见性修饰符。
/****************************************************
* 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;
};
}