I need help with my Java homework!
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 charges.
Modify the program so it calculates and displays the amount of money Packaage A customers would save if they purchased Packages B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
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 acess is provided.
4 answers
import java.text.DecimalFormat;
public class Bill{
public static void main(String[] args){
String input;
char servicePackage;
int hours=0;
int extrahours=0;
double charges=0.0;
int totalHours = 0;
final double BASE_RATE_A = 9.95;
final double BASE_RATE_B = 13.95;
final double BASE_RATE_C = 19.95;
final int BASE_HOUR_A = 10;
final int BASE_HOUR_B = 20;
final double PER_HOUR_A = 2.00;
final double PER_HOUR_B = 1.00;
Scanner kb = new Scanner(System.in);
DecimalFormat fmt = new DecimalFormat("$##.00");
System.out.print("Service package (A, B, or C): ");
input = kb.nextLine();
servicePackage = input.charAt(0);
if(servicePackage == 'A'){
System.out.print("Number of hours: ");
hours = kb.nextInt();
if(hours<=10){
charges = BASE_RATE_A;
System.out.println("Total Charges: "+fmt.format(charges));
}
else{
extrahours=hours-BASE_HOUR_A;
charges = BASE_RATE_A +(extrahours*PER_HOUR_A);
System.out.println("Total Charges: "+fmt.format(charges));
}
}
else if(servicePackage == 'B'){
System.out.print("Number of hours: ");
hours = kb.nextInt();
if(hours<=20){
charges = BASE_RATE_B;
System.out.println("Total Charges: "+fmt.format(charges));
}
else{
extrahours=hours-BASE_HOUR_B;
charges = BASE_RATE_B+(extrahours*PER_HOUR_B);
System.out.println("Total Charges: "+fmt.format(charges));
}
}
else if(servicePackage == 'C'){
System.out.print("Number of hours: ");
hours = kb.nextInt();
charges = BASE_RATE_C;
System.out.println("Total Charges: "+fmt.format(charges));
}
}
}
==
hope this helps
but how would I do the second part?
"Modify the program so it calculates and displays the amount of money Packaage A customers would save if they purchased Packages B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed."
thanks,
Matt
Write a program that calculates a customer's monthly bill. It should ask the user via dialog box 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 charges in a dialog box. The input and out put must be done using the dialog boxes.
Modify the program so it calculates and displays the amount of money Packaage A customers would save if they purchased Packages B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
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 acess is provided.
Basic Service Fee Premium Channels Charge
Residential RM20.00
RM7.50 per channel
Business RM75.00 for the first 10 connections; RM10 for each additional connection RM20.00 per channel for any number of connections