In java basic code only! This is my program I have written so far. Only using sc
ID: 3755765 • Letter: I
Question
In java basic code only! This is my program I have written so far. Only using scanner class and basic java. I need to use switch and if statements like I did. It is not displaying the total bill calculations correctly or doing the part 2 of the problem at all . Can someone fix my code so it works and compiles 100% correct. Don’t add advanced code just use what I have thanks!import java.util.*Scanner;
public class InternetServiceProvider 2 { public static void main(String[] args) { String userInput;
char packageChosen; double packageA,packageB,totalHours, totalSavingsAtoB, totalSavingsAtoC, totalSavingsBtoC;
totalSavingsAtoB = (packageA - 13.95); totalSavingsAtoC = (packageA - 19.95); totalSavingsBtoC = (packageB - 19.95);
Scanner keyboard = new Scanner(System.in); System.out.println("Which package have you obtain? (Please use A, B, or C)"); userInput = keyboard.nextLine(); packageChosen = userInput.charAt(0);
switch (packageChosen) {
case 'A': System.out.println("What are the total amount of hours used for this month?"); totalHours = keyboard.nextDouble(); if (totalHours <= 10) { packageA = 9.95 * totalHours; System.out.print("For Package A: The total charges for this month is $ " + packageA); System.out.print(" You save a total of " + totalSavingsAtoB + "if you chose Package B " + "and you would have save a total of " + totalSavingsAtoC + "if you chose Package C."); } else
packageA = 9.95 + (totalHours * 2.00); System.out.print("For Package A: The total charges for this month is $ " + packageA);
if (totalSavingsAtoB > packageA) { totalSavingsAtoB = (packageA - 13.95); totalSavingsAtoC = (packageA - 19.95); System.out.print(" You save a total of " + totalSavingsAtoB + "if you chose Package B " + "and you would have save a total of " + totalSavingsAtoC + "if you chose Package C.");
} break; case 'B': System.out.println("What are the total amount of hours used for this month?"); totalHours = keyboard.nextDouble(); if (totalHours <= 20) { packageB = 13.95 * totalHours; System.out.print("For Package B: The total charges for this month is $" + packageB); System.out.print("You would have save a total of " + totalSavingsBtoC + ", if you have chosen Package C."); } else { packageB = 13.95 + (totalHours * 1.00); System.out.print("For Package B: The total charges for this month is $" + packageB); System.out.print("You would have save a total of " + totalSavingsBtoC + ", if you have chosen Package C."); } if (totalSavingsAtoB > packageA) { totalSavingsBtoC = (packageB - 19.95); System.out.print(" You save a total of " + totalSavingsAtoB + "if you chose Package B " + "and you would have save a total of " + totalSavingsAtoC + "if you chose Package C.");
} break; case 'C': System.out.print("For Package C: The total charge for this is $19.95."); System.out.print(" Thank you for using our service! " ); break; default: System.out.print("Invalid entry, Please try again."); }
} 13. Internet Service Provider An Internet service provider has three different subscription packages for its customers: Package A: For $9.95 per month 10 hours of access are provided. Additional hours Package B: For $13.95 per month 20 hours of access are provided. Additional hours Package C: For $19.95 per month unlimited access is provided. Write a program that calculates a customer's monthly bill. It should ask the user to enter are $2.00 per hour. are $1.00 per hour. the letter of the package the customer has purchased (A, B, or C) and the number of hours that were used. It should then display the total chariges. 14. Internet Service Provider, Part 2 Modify the program you wrote for Programming Challenge 13 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
Explanation / Answer
import java.util.Scanner;
public class InternetServiceProvider
{
public static void main(String[] args)
{
String userInput;
char packageChosen;
double packageA,packageB,totalHours;
Scanner keyboard = new Scanner(System.in);
System.out.println("Which package have you obtain? (Please use A, B, or C)");
userInput = keyboard.nextLine();
packageChosen = userInput.charAt(0);
switch (packageChosen)
{
case 'A':
System.out.println("What are the total amount of hours used for this month?");
totalHours = keyboard.nextDouble();
if (totalHours <= 10)
{
packageA = 9.95;
System.out.print("For Package A: The total charges for this month is $ " + packageA);
System.out.print(" You save a total of $" + (13.95-9.95) + "if you chose Package B "
+ "and you would have save a total of $" + (19.95-9.95) + "if you chose Package C.");
}
else
packageA = 9.95 + ((totalHours-10) * 2.00);
System.out.print("For Package A: The total charges for this month is $ " + packageA);
packageB = totalHours<20?13.95:13.95 + ((totalHours-20) * 1.00);
if(packageA>packageB) {
System.out.print(" You save a total of $" + (packageA-packageB) + " if you chose Package B");
}
if(packageA>19.95) {
System.out.print(" You save a total of $" + (packageA-19.95) + " if you chose Package C");
}
break;
case 'B':
System.out.println("What are the total amount of hours used for this month?");
totalHours = keyboard.nextDouble();
if (totalHours <= 20)
{
packageB = 13.95 ;
System.out.print("For Package B: The total charges for this month is $" + packageB);
System.out.print(" You are saving $ " + (19.95-13.95) + " if you chose Package C");
}
else
{
packageB = 13.95 + ((totalHours-20) * 1.00);
System.out.print("For Package B: The total charges for this month is $" + packageB);
if(packageB>19.95) {
System.out.print(" You save a total of $" + (packageB-19.95) + " if you chose Package C");
}
}
break;
case 'C':
System.out.print("For Package C: The total charge for this is $19.95.");
System.out.print(" Thank you for using our service! " );
break;
default:
System.out.print("Invalid entry, Please try again.");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.