Question: Modify this program so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C,

Modify this program so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, and the amount of money Package B customers would save if they purchased Pack-age C. If there would be no savings, no message should be printed.

You can use decimal formatter class to format the output. DecimalFormat Decformatter = new DecimalFormat("#0.00"); Decformatter.format(outputvariable));

--------------------------------------------------------------------------------------------------------------------------------------

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the letter of the package purchased: "); char packageLetter = input.next().charAt(0); System.out.println("Enter the number of hours that were used: "); int hoursUsed = input.nextInt(); double totalCharges = 0; if (packageLetter == 'A') { totalCharges = 9.95; if (hoursUsed > 10) { totalCharges += (hoursUsed - 10) * 2.0; } } else if (packageLetter == 'B') { totalCharges = 13.95; if (hoursUsed > 20) { totalCharges += (hoursUsed - 20) * 1.0; } } else if (packageLetter == 'C') { totalCharges = 19.95; } else { System.out.println("Your total charges are $13.95"); System.exit(0); } System.out.println("Your total charges are $" + String.format("%.2f", totalCharges)); } }

------------------------------------------------------------------------------------------------------------------------------------------

Test Case 1:

Enter the letter of the package purchased: A Enter the number of hours that were used: 17 Your total charges are $23.95 You would have saved $10.00 if you had gotten package B You would have saved $4.00 if you had gotten package C

Test Case2:

Enter the letter of the package purchased: B Enter the number of hours that were used: 30 Your total charges are $23.95 You would have saved $4.00 if you had gotten package C

Test Case3:

Enter the letter of the package purchased: C Enter the number of hours that were used: 40 Your total charges are $19.95

Test Case4:

Enter the letter of the package purchased: D Enter the number of hours that were used: 30 That package input was not an option.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!