Check ALL the {
make sure that there is a } that pairs with it.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Check ALL the {
make sure that there is a } that pairs with it.
package lesson2.skowronek;
import java.util.Scanner; //Needed for the scanner class
public class Ex3_13 {
public static void main(String[] args) {
String input; //To hold users input.
char selectPackage; //To hold Internet Package
double hourUsage, totalCharges, addCharges; //other variables
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//Prompt the user to select a Internet Package.
System.out.print("Please select the package that you have purchase.");
input = keyboard.nextLine();
selectPackage = input.charAt(0);
System.out.print("Please select the amount of hours used.");
input = keyboard.nextLine();
hourUsage = Double.parseDouble(input);
//Display pricing for selected package...
switch (selectPackage)
{
case 'a':
case 'A':
if (hourUsage > 10)
{
addCharges = hourUsage - 10;
totalCharges = (addCharges * 2.0) + 9.95;
System.out.println("You have used " + hourUsage + " hours and your total is $" + totalCharges + " per month. ");
}
else
{
System.out.println("Your total is $9.95 per month.");
}
break;
case 'b':
case 'B':
if (hourUsage > 20 )
{
addCharges = hourUsage - 20;
totalCharges = (addCharges * 1.0) + 13.95;
System.out.println("You have used " + hourUsage + " and your total is $" + totalCharges + " per month.");
}
else
{
System.out.println("Your total is $13.95 per month.");
}
break;
case 'c':
case 'C':
System.out.println("Your total is $19.95 per month.");
break;
default:
System.out.println("Invalid Choice.");
}
}
}
Go ahead and try this out, I had to due the same problem for my class and it worked nicely. The suggestion from one of your peers on this site to use an if statement was a good one. If you look in the book, generally the code assignments require that you use what was reflected in the chapter. As you pick up more concepts, tried to incorporate material covered in previous chapters when necessary. If you don't use it, you will lose it.