In: Computer Science
wirte a program in java
Part I 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
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 Internet Service Provider
Modify the program you wrote for Programming in part 1 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 If there would be no savings, no message should be printed.
use printf for output and no arrays
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
import java.util.Scanner;
public class ServiceCalculator {
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':
// checking if
user used less than 5 GB else calculating additional charges
if (hoursUsed
<= 10) {
monthlyBill = 9.95;
} else {
monthlyBill = 9.95 + ((hoursUsed -10) *
2);
}
break;
case 'B':
// checking if
user used less than 10 GB else calculating additional charges
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
}
}
2)
import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
class InternetProviderPart2
{
public static void main(String[] args)
{
int hours;
double packageA_amount,
packageB_amount,packageC_amount;
double total_amount=0;
DecimalFormat formatter =
new DecimalFormat(" 0.00");
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter hours:");
hours=keyboard.nextInt();
if(hours<10)
packageA_amount=9.95;
else
packageA_amount=9.95+((hours-10)*2);
if(hours<20)
packageB_amount=14.95;
else
packageB_amount=14.95+((hours-20)*1);
packageC_amount=19.95;
double difference;
difference=packageA_amount- packageB_amount;
System.out.println("Package A customer would save $"
+formatter.format(difference)+ " than Package B");
difference=packageA_amount - packageC_amount;
System.out.println("Package A customer would save $"
+formatter.format(difference)+ " than Package C");
difference=packageB_amount - packageC_amount;
System.out.println("Package B customer would save $"
+formatter.format(difference)+ " than Package C");
System.exit(0);
}
}
Kindly revert for any queries
Thanks.