In: Computer Science
Internet Service provider Part 1 (Java Program)
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 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.
Part 2
Modify the program you wrote for Part 1 so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, the amount of money Package B customers would save if they purchased Package A or Package C, and the amount of money Package C customers would save if they purchased Package A or Package B . If there would be no savings, no message should be printed.
Answer 1:
import java.util.Scanner;
public class MonthlyBillCalculator {
public static void main(String[] args) {
// scanner to read data from
user
Scanner sc = new
Scanner(System.in);
char Package;
double hoursUsed;
double monthlyBill = 0;
// starting infinite loop to get
valid inputs from user
while (true) {
// reading
type of package from user
System.out.print("Enter Package (A/B/C) :");
Package =
sc.next().charAt(0);
// reading data
from user
System.out.print("Enter number of hours used :");
hoursUsed =
sc.nextDouble();
// checking if
inputs are valid than comes out of the loop
if ((Package ==
'A' || Package == 'B' || Package == 'C') && (hoursUsed
>= 0 && hoursUsed <= 50)) {
break;
} else {
System.out.println("\nInvalid Input\n\nEnter the
details again\n--------------------");
}
}
// starting to switch to calculate
based user selected package
switch (Package) {
// if selected type is A
case 'A':
if (hoursUsed
<= 10) {
monthlyBill = 9.95;
} else {
monthlyBill = 9.95 + ((hoursUsed -10) *
2);
}
break;
case 'B':
if (hoursUsed
<= 10) {
monthlyBill = 13.95;
} else {
monthlyBill = 13.95 + ((hoursUsed - 20) *
1);
}
break;
case 'C':
monthlyBill =
19.95;
break;
}
System.out.printf("\nMonthly bill =
$%.2f\n", monthlyBill);
// based on usage suggesting
Package type for user
}
}
Answer 2:
import java.util.Scanner;
public class MonthlyBillCalculator {
public static void main(String[] args) {
// scanner to read data from
user
Scanner sc = new
Scanner(System.in);
char Package;
double hoursUsed;
double monthlyBill = 0;
// starting infinite loop to get
valid inputs from user
while (true) {
// reading
type of package from user
System.out.print("Enter Package (A/B/C) :");
Package =
sc.next().charAt(0);
// reading data
from user
System.out.print("Enter number of hours used :");
hoursUsed =
sc.nextDouble();
// checking if
inputs are valid than comes out of the loop
if ((Package ==
'A' || Package == 'B' || Package == 'C') && (hoursUsed
>= 0 && hoursUsed <= 50)) {
break;
} else {
System.out.println("\nInvalid Input\n\nEnter the
details again\n--------------------");
}
}
// starting to switch to calculate
based user selected package
switch (Package) {
// if selected type is A
case 'A':
if (hoursUsed
<= 10) {
monthlyBill = 9.95;
} else {
monthlyBill = 9.95 + ((hoursUsed - 10) *
2);
}
System.out.printf("\nMonthly bill = $%.2f\n", monthlyBill);
if (monthlyBill
> 19.5) {
System.out.println("If you take Package C than
you could have saved " + (monthlyBill - 19.95));
}
else if
(monthlyBill > 13.95) {
System.out.println("If you take Package B than
you could have saved " + (monthlyBill - 13.95));
}
break;
case 'B':
if (hoursUsed
<= 10) {
monthlyBill = 13.95;
} else {
monthlyBill = 13.95 + ((hoursUsed - 20) *
1);
}
System.out.printf("\nMonthly bill = $%.2f\n", monthlyBill);
if (monthlyBill
> 19.5) {
System.out.println("If you take Package C than
you could have saved " + (monthlyBill - 19.95));
}
break;
case 'C':
monthlyBill =
19.95;
break;
}
System.out.printf("\nMonthly bill =
$%.2f\n", monthlyBill);
// based on usage suggesting
Package type for user
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me