Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

Students also viewed these Databases questions

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago