Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In basic java code only please complete the problem below. Only use the scanner

ID: 3755785 • Letter: I

Question

In basic java code only please complete the problem below. Only use the scanner class. * NO(joptionpane)* Please use SWITCH and IF statements for both of the problems. Please make sure the program compiles and works 100 %! In basic java code only please complete the problem below. Only use the scanner class. * NO(joptionpane)* Please use SWITCH and IF statements for both of the problems. Please make sure the program compiles and works 100 %! oter 3 Decision Structures 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. are $2.00 per hour. are $1.00 per hour. Write a program that calculates a customer's monthly bill. It should ask the user to enter 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 charges. 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

For Challenge 13, below is the program

import java.util.Scanner;

public class ISP

{

public static void main(String[] args)

{

//declare variables to hold the bill amount for each package

double packageA = 9.95, packageB = 13.95, packageC = 19.95;

//declare variables to hold number of hours available for each package, which will be used calculate the bill later

//No variable required for package C, since it has unlimited Usage

int packageaHrs = 10, packagebHrs = 20;

//Initialize scanner

Scanner sc = new Scanner(System.in);

//Accept user input for Package. Provide the available options

System.out.print("Please enter your Package Letter (A OR B OR C): ");

String Ipackage = sc.nextLine();

//Accept user input for number of hours used

System.out.print("Please enter the number of hours used: ");

//This throws an exception if user enters string. This exception is excepected when you try to read any input and type cast in scanner

int hours = sc.nextInt();

//declare a variable to hold user bill amount

double userBill = 0;

//switch to user provided package

switch (Ipackage)

{

//If package is A

case "A" :

//Check if number of usage hours is withen the limit of package

if(hours<= packageaHrs)

{

//Assign the package amount

userBill = packageA;

}

else

{

//Calculate the extra amount. i.e $2 per every hour

//Minus the total hours by 10, since that is the usage hours of package and then multiply the remaining with 2

//Total User bill will be packae amount plus extra bill

userBill = packageA + (hours - packageaHrs) * 2;

}

break;

case "B" :

//Check if number of usage hours is withen the limit of package

if(hours<= packagebHrs)

{

//Assign the package amount

userBill = packageB;

}

else

{

//Calculate the extra amount. i.e $1 per every hour

//Minus the total hours by 20, since that is the usage hours of package and then multiply the remaining with 1

//Total User bill will be packae amount plus extra bill

userBill = packageB + (hours - packagebHrs) * 1;

}

break;

case "C" :

//No need to calculate any bill, since package C provides Unlimited usage

userBill = packageC;

break;

//If package entered is other than A, B or C, consider that as invalid option and terminate the program

default:

System.out.println("Invalid Package Selected!");

System.exit(0);

}

//Close the Screener

sc.close();

//Print the user input to confirm and Calculated bill amount

    System.out.println();

System.out.println("Your Package Is: "+Ipackage);

System.out.println("Number of hours used Is: "+ hours);

    System.out.println("Your monthly bil Is: $"+ userBill);     

}

}

For Challenge 14, Below is the modified program

import java.util.Scanner;

public class ISP

{

public static void main(String[] args)

{

//declare variables to hold the bill amount for each package

double packageA = 9.95, packageB = 13.95, packageC = 19.95;

//declare variables to hold number of hours available for each package, which will be used calculate the bill later

//No variable required for package C, since it has unlimited Usage

int packageaHrs = 10, packagebHrs = 20;

//Initialize scanner

Scanner sc = new Scanner(System.in);

//Accept user input for Package. Provide the available options

System.out.print("Please enter your Package Letter (A OR B OR C): ");

String Ipackage = sc.nextLine();

//Accept user input for number of hours used

System.out.print("Please enter the number of hours used: ");

//This throws an exception if user enters string. This exception is excepected when you try to read any input and type cast in scanner

int hours = sc.nextInt();

//declare a variable to hold user bill amount

double userBill = 0;

String amountSavedIfB = "";

String amountSavedIfC = "";

//switch to user provided package

switch (Ipackage)

{

//If package is A

case "A" :

//Check if number of usage hours is withen the limit of package

if(hours<= packageaHrs)

{

//Assign the package amount

userBill = packageA;

}

else

{

//Calculate the extra amount. i.e $2 per every hour

//Minus the total hours by 10, since that is the usage hours of package and then multiply the remaining with 2

//Total User bill will be packae amount plus extra bill

userBill = packageA + (hours - packageaHrs) * 2;

double userBillIfB = 0;

if(hours<= packagebHrs)

{

//Assign the package amount

userBillIfB = packageB;

}

else

{

//Calculate the extra amount. i.e $1 per every hour

//Minus the total hours by 20, since that is the usage hours of package and then multiply the remaining with 1

//Total User bill will be packae amount plus extra bill

userBillIfB = packageB + (hours - packagebHrs) * 1;

}

// Check if user bill is between package B and Package C amount. If true, display the amount saved, if Package C is purchased

if(userBill > userBillIfB){

amountSavedIfB = "If you purchase Package B, you will save $" + (int)(userBill - userBillIfB);

}

// Check if user bill is higher than package C amount. If true, display the amount saved, if Package C is purchased

if(userBill > packageC){

amountSavedIfC = "If you purchase Package C, you will save $" + (int)(userBill - packageC);

}

}

break;

case "B" :

//Check if number of usage hours is withen the limit of package

if(hours<= packagebHrs)

{

//Assign the package amount

userBill = packageB;

}

else

{

//Calculate the extra amount. i.e $1 per every hour

//Minus the total hours by 20, since that is the usage hours of package and then multiply the remaining with 1

//Total User bill will be packae amount plus extra bill

userBill = packageB + (hours - packagebHrs) * 1;

}

//Check if user bill is higher than package C amount. If true, display the amount saved, if Package C is purchased

if(userBill > packageC){

amountSavedIfC = "If you purchase Package C, you will save $" + (int)(userBill - packageC);

}

break;

case "C" :

//No need to calculate any bill, since package C provides Unlimited usage

userBill = packageC;

break;

//If package entered is other than A, B or C, consider that as invalid option and terminate the program

default:

System.out.println("Invalid Package Selected!");

System.exit(0);

}

//Close the Screener

sc.close();

//Print the user input to confirm and Calculated bill amount

    System.out.println();

System.out.println("Your Package Is: "+Ipackage);

System.out.println("Number of hours used Is: "+ hours);

    System.out.println("Your monthly bill Is: $"+ userBill);    

    System.out.println(amountSavedIfB);     

    System.out.println(amountSavedIfC);     

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote