为什么 planATotalPrice 没有执行?

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();


斯蒂芬大帝
浏览 128回答 2
2回答

芜湖不芜

你之所以得到这个,是因为你已经声明了变量 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基本上计算机不知道它会/应该使用哪一个。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java