This is the task:
Task #1 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 (integer) that were used. It should then display the total charges. If an invalid package (other than A, B, or C) or invalid number of hours (<0 or > 30*24) is input, the program should display an appropriate error message and stop.
So the input must be either 'A', 'B', or 'C' and anything else should send a message saying "invalid input" and not ask me for more info.
i should be getting:
Enter the customer's package (A, B, or C): a
Invalid package. Enter A, B, or C.
but i get:
Enter the customer's package (A, B, or C): a
Enter the number of hours used:
Invalid package. Enter A, B, or C.
if the input is invalid, i dont want it to ask me for hours.
PLEASE HELP!
heres the code:
import java.util.Scanner;
public class TestInternetPart1
{
public static void main(String[] args)
{
int hours=1;
double totalCharges;
int additionalHours;
// Create a Scanner object to read input
Scanner keyboard = new Scanner(System.in);
// Get the letter of the package
System.out.print("Enter the customer's package (A, B, or C): ");
String inputLetter = keyboard.nextLine();
char internetPackage = inputLetter.charAt(0);
// Get number of hours.
System.out.print("Enter number of hours: ");
hours = keyboard.nextInt();
if (internetPackage == 'A' && hours > 10)
{
additionalHours = hours - 10;
totalCharges = 9.95 + (additionalHours * 2.00);
System.out.println("Your monthly bill is $" + totalCharges + ".");
}
else if (internetPackage == 'A' && hours < 10)
{
System.out.println("Your monthly bill is $9.95.");
}
else if (internetPackage == 'B' && hours > 20)
{
additionalHours = hours - 20;
totalCharges = 13.95 + (additionalHours * 1.00);
System.out.println("Your monthly bill is $" + totalCharges + ".");
}
else if (internetPackage == 'B' && hours < 20)
{
System.out.println("Your monthly bill is $13.95.");
}
else if (internetPackage == 'C')
{
System.out.println("Your monthly bill is $19.95.");
}
else
System.out.println("Invalid input. Please enter either A, B, or C.");
System.exit(0);
}
}