An Internet service provider has three different subscription packages for its c
ID: 3676767 • Letter: A
Question
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 are $2.00 per hour.
Package B For $13.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
Package C For $19.95 per month unlimited access is provided.
Write a program InternetServiceProviderPart1.java 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 (integer) that were used. It should then display the total charges. If an invalid package (other than A, B, or C) or invalid number of hours (<0 or > 30*24) is input, the program should display an appropriate error message and stop.
You should use the DecimalFormat class to define the format pattern and print total charges with $ in the front and two digits after decimal point with trailing zeros displayed.
The following are sample interactions that occur when running the program, in bold are the user's input:
Test 1:
Enter the customer's package (A, B, or C): a Invalid package. Enter A, B, or C.
Test 2:
Enter the customer's package (A, B, or C): B
Enter the number of hours used: 721 Invalid input, please enter number of hours between 0 and 720.
Test 3:
Enter the customer's package (A, B, or C): C
Enter the number of hours used: 0 The charges are $19.95
Test 4:
Enter the customer's package (A, B, or C): A
Enter the number of hours used: 20 The charges are $29.95
Test 5:
Enter the customer's package (A, B, or C): B
Enter the number of hours used: 20 The charges are $13.95
Explanation / Answer
InternetServiceProviderPart1.java
import java.io.BufferedReader;//bufferedreader class for keyboard iputting
import java.io.IOException;//for IOException
import java.io.InputStreamReader;//reads input valus
import java.util.Scanner;//keyboard inputing
public class InternetServiceProviderPart1 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));//keybard in putting
System.out.println("Enter the plan");
Scanner sc = new Scanner(System.in);//keybard in putting
char plan = (char) br.read();//type casting
int noofhours;
float Charges;
switch (plan) {//switch case
case 'A'://if case=A
Charges = 9.95f;
System.out.println("Enter the no of hours:");
noofhours = sc.nextInt();
if (plan == 'A' && noofhours > 0 && noofhours <= 10) {//if else statement
System.out.println("Charges :" + Charges);
} else if (plan == 'A' && noofhours > 10 && noofhours <= 720) {
noofhours = noofhours - 10;
Charges = Charges + 2 * (noofhours);
System.out.println("Charges =" + Charges);
} else if (plan == 'A' && noofhours > 720 || noofhours < 0) {
System.out.println("Invalid Input");
}
break;
case 'B'://if case=B
Charges = 13.95f;
System.out.println("Enter the no of hours:");
noofhours = sc.nextInt();
if (plan == 'B' && noofhours > 0 && noofhours <= 20) {
} else if (plan == 'B' && noofhours > 20 && noofhours <= 720) {
noofhours = noofhours - 20;
Charges = Charges + 1 * (noofhours);
System.out.println("Charges =" + Charges);
} else if (plan == 'B' && noofhours > 720 || noofhours < 0) {
System.out.println("Invalid Input");
}
break;
case 'C'://if case=C
Charges = 19.95f;
System.out.println("Enter the no of hours:");
noofhours = sc.nextInt();
if (plan == 'C' && noofhours >= 0 && noofhours <= 720) {
System.out.println("Charges" + Charges);
} else if (plan == 'C' && noofhours > 720 || noofhours < 0) {
System.out.println("Invalid Input");
}
break;
default:
System.out.println("INVALID CHOICE");
break;
}
}
}
javac InternetServicePorviderPart1.java
java InternetServicePorviderPart1
run:
Enter the plan
B
Enter the no of hours:
24
Charges =17.95
BUILD SUCCESSFUL (total time: 4 seconds)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.