Reply
Old 09-16-2013, 02:05 AM   #1 (permalink)
ace
 
Status: Member
Posts: 83



Default java programming hmwk help. done with overall, just need help on last part.

An Internet service provider has three different subscription packages for its customers:

Package A: $9.95 per month for 10 hours access. Additional hours are $2.00 per hour

Package B: $13.95 per month for 20 hours access. Additional hours are $1.00 per hour

Package C: $29.99 per month for unlimited access.

Write a program that calculates a customer's monthly bill. The program should ask the user to enter the letter of the package the customer purchased (A, or B, or C) and the number of hours that we used. It should calculate and display the total charges.

The program should also calculate and display 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 C. If there would be no savings, no message should be displayed.




I am stuck with this part "The program should also calculate and display 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 C. If there would be no savings, no message should be displayed." I'm confused with the calculation.... Please help.

Here's my code:

import java.util.Scanner;

public class hmwk
{
public static void main(String[] args)
{
char packageLetter;
int hoursUsed;
int regularHours;
int extraHours;
double monthlyFee;
double extraHoursFee;
double totalFee;
String input;


Scanner keyboard = new Scanner(System.in);


System.out.println("Enter the letter of the internet package you purchased (A, B, or C): ");
input = keyboard.nextLine();
packageLetter = input.charAt(0);

while(packageLetter != 'A' && packageLetter != 'B' && packageLetter != 'C')
{
System.out.print("Error. Enter ONLY A, B, or C. ");
System.out.println("\n\nEnter the letter of the internet package you purchased (A, B, or C): ");
input = keyboard.nextLine();
packageLetter = input.charAt(0);
}


System.out.println("Enter the number of hours you used: ");
hoursUsed = keyboard.nextInt();



switch(packageLetter)
{
case 'A':
monthlyFee = 9.95;
regularHours = 10;
extraHours = hoursUsed - regularHours;
extraHoursFee = extraHours * 2.00;
totalFee = monthlyFee + extraHoursFee;
System.out.println("The total charge is $" + totalFee + ".");
break;
case 'B':
monthlyFee = 13.95;
regularHours = 20;
extraHours = hoursUsed - regularHours;
extraHoursFee = extraHours * 1.00;
totalFee = monthlyFee + extraHoursFee;
System.out.println("The total charge is $" + totalFee + ".");
break;
case 'C':
totalFee = 29.99;
System.out.println("The total charge is $" + totalFee + ".");
break;
default:
System.out.println("Enter either A,B, " +
"or C).");
}

System.exit(0);



}
}
ace is offline   Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java hmwk help!? yishunshin Programming Languages 0 03-07-2014 02:05 AM
c programming hmwk help? ace Programming 0 03-11-2013 03:04 AM
c programming hmwk (need help)? ace Coding 1 03-06-2013 09:04 PM
c programming hmwk (need help)? ace Coding 1 03-04-2013 06:06 AM
Beginner Java hmwk help!? Unknown_User Coding 3 01-30-2012 04:36 AM