An internet service provide offers three different subscription packages: Packag
ID: 3795161 • Letter: A
Question
An internet service provide offers three different subscription packages: Package 1: dollar 15.95 a month for up to 10 hours of service. Additional hours are dollar 2.00 per hour. Package 2: dollar 20.95 a month for up to 20 hours of service. Additional hours are dollar 1.00 per hour. Package 3: dollar 30.99 per month unlimited access. Write a program which does the following: Ask the user which plan they have. Ask the user for the month number (1-12) of which month they are being billed. Ask the user how many hours they used. Display the cost of their bill. Also display how much money Package 1 customers would would have saved if they purchased packages 2 or 3. and how much money Package 2 customers would have saved if they purchased Package 3. If there were no savings, do not display this message. The plan number cannot be negative. The plan number must be a value [1, 3], The number of hours cannot be negative. The number of hours cannot exceed the total number of hours for a given month. Months with 30 days have 720 hours, months with 31 days have 744 hours. February with 28 days has 672 hours (don't worry about leap years). Validate that the user does not enter a value greater than the total hours for a given month. See the table belowExplanation / Answer
import java.text.DecimalFormat;
import java.util.Scanner;
public class BillGenerator {
public static void main(String [] args) {
double maxHours = 0.0;
int plan;
double actualHours;
int noOfMonth;
double amountSavedPlan2 = 0.0;
double amountSavedPlan3 = 0.0;
double bill = 0.0;
System.out.print("Enter the Plan: ");
Scanner sc = new Scanner(System.in);
plan = sc.nextInt();
if (plan < 1 || plan > 3) {
System.out
.println("Invalid plan. Plan number must be a value [1,3]");
System.exit(0);
}
System.out
.print("Enter the Number of Month for which you are being billed: ");
noOfMonth = sc.nextInt();
if (noOfMonth < 1 || noOfMonth > 12) {
System.out.println("Invalid Month. Month must be a value [1,12]");
System.exit(0);
} else if (noOfMonth == 2) {
maxHours = 672;
} else if (noOfMonth == 4 || noOfMonth == 6 || noOfMonth == 9
|| noOfMonth == 11) {
maxHours = 720;
} else {
maxHours = 744;
}
System.out.println("Enter the number of hours you used the service: ");
actualHours = sc.nextDouble();
if (actualHours > maxHours || actualHours < 0) {
System.out
.println("Invalid value.The number of hours can not be a negative value and "
+ "Hours used can not exceed the total number of hours for a given month.");
System.exit(0);
}
if (plan == 1) {
if (actualHours <= 10) {
bill = 15.95;
} else {
bill = 15.95 + (2 * (actualHours-10));
amountSavedPlan2 = (15.95 + (2 * (actualHours-10))) - (20.95
+ (1 * (actualHours-10)));
amountSavedPlan3 = (15.95 + (2 * (actualHours-10))) - 30.99;
}
} else if (plan == 2) {
if (actualHours <= 20) {
bill = 20.95;
} else {
bill = 20.95 + (1 * (actualHours-20));
amountSavedPlan3 = 20.95 + (1 * (actualHours-20)) - 30.99;
}
} else {
bill = 30.99;
}
DecimalFormat df = new DecimalFormat("#.00");
df.format(bill);
System.out.println("Your Total bill for services used: $" + bill);
df.format(amountSavedPlan2);
df.format(amountSavedPlan3);
if (amountSavedPlan2 > 0 && amountSavedPlan3 > 0) {
System.out
.println("The Amount u would have saved with plan 2 and plan 3 are respictevely "
+ "$"+df.format(amountSavedPlan2) + "," + "$"+df.format(amountSavedPlan3));
}
else if(amountSavedPlan2 > 0){
System.out
.println("The Amount u would haved save with plan 2: "
+ "$"+df.format(amountSavedPlan2));
}
else if(amountSavedPlan3 > 0){
System.out
.println("The Amount u would haved save with plan 3: "
+ "$"+df.format(amountSavedPlan3));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.