This is the guidelines for the program I'm making:
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 > 31*24) is input, the program should display an appropriate error message and stop. Use if statements for input validation and use a switch statement to calculate total charges depending on the package the customer selected.
This is what I have in my program:
import java.util.Scanner;
public class InternetServiceProviderPart12
{
public static void main(String[] args)
{
char package;
int hours;
int packageHours;
int addedHours;
double monthlyCharge;
double addedHoursCharge;
double total;
Scanner kb = new Scanner(System.in);
System.out.print("Enter the customer's package (A, B, or C): ");
char package = kb.next().charAt(0);
kb.nextLine();
if (package != 'A'||package != 'B'||package != 'C')
{
System.exit(0);
}
System.out.print("Enter the number of hours used: ");
int hours = kb.nextInt();
kb.nextLine();
if (hours < 0||hours > 31 * 24)
{
System.exit(0);
} switch(package){
case 'A':
monthlyCharge = 9.95;
packageHours = 10;
addedHours = packageHours - hours;
addedHoursCharge = addedHours * 2.00;
total = monthlyCharge + addedHoursCharge;
System.out.println("The charges are $" + total);
break;
case'B': monthlyCharge = 13.95;
packageHours = 20;
addedHours = packageHours - hours;
addedHoursCharge = addedHours * 2.00;
total = monthlyCharge + addedHoursCharge;
System.out.println("The charges are $" + total);
break;
case 'C':
monthlyCharge = 19.95;
System.out.println("The charges are $" + total);
break;
default:
System.out.print("Invalid");
System.exit(0);
}
}
}
I keep getting these errors when compiling:
InternetServiceProviderPart12.java:8: not a statement
char package;
^
InternetServiceProviderPart12.java:8: ';' expected
char package;
^
InternetServiceProviderPart12.java:17: not a statement
char package = kb.next().charAt(0);
^
InternetServiceProviderPart12.java:17: ';' expected
char package = kb.next().charAt(0);
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: illegal start of expression
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:19: ';' expected
if (package != 'A'||package != 'B'||package != 'C')
^
InternetServiceProviderPart12.java:23: <identifier> expected
System.out.print("Enter the number of hours used: ");
^
InternetServiceProviderPart12.java:23: illegal start of type
System.out.print("Enter the number of hours used: ");
^
InternetServiceProviderPart12.java:25: <identifier> expected
kb.nextLine();
^
InternetServiceProviderPart12.java:26: illegal start of type
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: illegal start of type
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: <identifier> expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: ')' expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: ';' expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: illegal start of type
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: <identifier> expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: ';' expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: illegal start of type
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:26: <identifier> expected
if (hours < 0||hours > 31 * 24)
^
InternetServiceProviderPart12.java:27: ';' expected
{
^
InternetServiceProviderPart12.java:28: illegal start of type
System.exit(0);
^
InternetServiceProviderPart12.java:28: illegal start of type
System.exit(0);
^
InternetServiceProviderPart12.java:30: class, interface, or enum expected
switch(package){
^
InternetServiceProviderPart12.java:33: class, interface, or enum expected
packageHours = 10;
^
InternetServiceProviderPart12.java:34: class, interface, or enum expected
addedHours = packageHours - hours;
^
InternetServiceProviderPart12.java:35: class, interface, or enum expected
addedHoursCharge = addedHours * 2.00;
^
InternetServiceProviderPart12.java:36: class, interface, or enum expected
total = monthlyCharge + addedHoursCharge;
^
InternetServiceProviderPart12.java:37: class, interface, or enum expected
System.out.println("The charges are $" + total);
^
InternetServiceProviderPart12.java:38: class, interface, or enum expected
break;
^
InternetServiceProviderPart12.java:39: class, interface, or enum expected
case'B':
^
InternetServiceProviderPart12.java:41: class, interface, or enum expected
packageHours = 20;
^
InternetServiceProviderPart12.java:42: class, interface, or enum expected
addedHours = packageHours - hours;
^
InternetServiceProviderPart12.java:43: class, interface, or enum expected
addedHoursCharge = addedHours * 2.00;
^
InternetServiceProviderPart12.java:44: class, interface, or enum expected
total = monthlyCharge + addedHoursCharge;
^
InternetServiceProviderPart12.java:45: class, interface, or enum expected
System.out.println("The charges are $" + total);
^
InternetServiceProviderPart12.java:46: class, interface, or enum expected
break;
^
InternetServiceProviderPart12.java:47: class, interface, or enum expected
case 'C':
^
InternetServiceProviderPart12.java:49: class, interface, or enum expected
System.out.println("The charges are $" + total);
^
InternetServiceProviderPart12.java:50: class, interface, or enum expected
break;
^
InternetServiceProviderPart12.java:51: class, interface, or enum expected
default:
^
InternetServiceProviderPart12.java:53: class, interface, or enum expected
System.exit(0);
^
InternetServiceProviderPart12.java:54: class, interface, or enum expected
}
^
I know it's is a lot of errors and I know how to reduce it to 13 errors. I'm in quite a hurry and need to finish it by tomorrow. All I really care about on fixing is the errors for char, using package, and the switch. Please help. Thank-you.