Question: Need help modifying my code: Internet Service provider, part 2 Modify the program you wrote for Programming Challenge 13(Previous Program) so it also calculates and
Need help modifying my code:
Internet Service provider, part 2 Modify the program you wrote for Programming Challenge 13(Previous 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 Package C. If there would be no savings, no message should be printed.
This is my code below
import java.util.*;
public class InternetServiceProvider {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here // declare variables double usageCharge; int extraHours = 0; int hours = 0; // create scanner object to read input Scanner in = new Scanner(System.in); // prompt user to enter package selection System.out.print("Enter the letter of the package purchased: "); // convert either to uppercase or lowercase user input char p = in.next().charAt(0); if(Character.isLowerCase(p)) p = Character.toUpperCase(p); System.out.println(); if(p!='C') { // prompt user to enter number of hours used System.out.print("Enter the number of hours that were used: "); hours=in.nextInt(); } switch(p) {
case 'A': if(hours > 10) extraHours = hours - 10; usageCharge= 9.95 + (extraHours * 2.00); System.out.println("Your total charges are $"+usageCharge); break;
case 'B': if(hours > 20) extraHours = hours - 20; usageCharge = 13.95 + (extraHours * 1.00); System.out.println("Your total charges are $"+usageCharge); break;
case 'C': if (hours > 0) System.out.println("Your total charges are $9.95"); break;
default: System.out.println("That package input was not an option"); } }
Must pass following test cases:
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
Get step-by-step solutions from verified subject matter experts
