import java.util.Scanner;//Needed for the Scanner class/** * 程序要求用戶輸入客戶購買的包裹的字母 (A,B,C) * 和使用的小時數。* 然后程序將計算客戶的每月賬單。* 套餐 A:每月 9.95 美元,包括 10 小時的互聯網服務。額外的小時數為每小時 2 美元。* 套餐 B:每月 13.95 美元,包括 20 小時的互聯網服務。額外的小時數為每小時 1 美元。* 套餐 AC:每月 19.95 美元,提供無限上網服務。* * 程序計算并顯示 A 套餐客戶在 * 購買套餐 B 或 C 時可節省的金額,以及套餐 B 客戶在 * 購買 C 時可節省的金額。 */public class InternetSavingsCh3 { public static void main(String[] args) // main 方法開始執行 Java 應用程序 { String input; // 保存用戶的輸入 double planAFixedPrice = 9.95; double planBFixedPrice = 13.95; double planCFixedPrice = 19.95; // to hold the final monthly bill double planAIncludedHours = 10.00; // total hours for interner plan double plaBIncludedHours = 20.00; // total hours for interner plan double planCIncludedHours = 0.0; // total hours for interner plan double planAExtraHours,planBExtraHours, planCExtraHours; double planAPricePerExtraHour = 2.0; // to hold the amount of charged for additional hours of internet use double planBPricePerExtraHour = 1.0; // to hold the amount of charged for additional hours of internet use double planCPricePerExtraHour = 0.0; // to hold the amount of charged for additional hours of internet use double planASavingsOnPlanB, planASavingsOnPlanC, planBSavingsOnPlanC;// to hold the amount of savings per package double planATotalPrice, planBTotalPrice, planCTotalPrice; double totalHours; // to hold the total hours the Internet was used Scanner keyboard = new Scanner(System.in); //create an object to read input from the standard input channel System.in (typically, the keyboard) System.out.println(" Enter the letter of the Internet package you have purchased A,B,or C: "); // prompt the user for the internet package input = keyboard.nextLine(); char packageInternet = input.charAt(0); // Internet package selected by the user System.out.println(" Enter the total number of hours you used the Internet this month: "); //display instructions totalHours = keyboard.nextDouble();
2 回答

蕪湖不蕪
TA貢獻1796條經驗 獲得超7個贊
你之所以得到這個,是因為你已經聲明了變量 2 次并且范圍重疊......在這種情況下你聲明了一次:
double planASavingsOnPlanB, planASavingsOnPlanC, planBSavingOnPlanC;// to hold the amount of savings per package
和
double planASavingsOnPlanB = planATotalPrice - planBFixedPrice; //compute the amount saved if purchasing plan B instead of plan A
基本上計算機不知道它會/應該使用哪一個。
添加回答
舉報
0/150
提交
取消