|
-
Jan 25th, 2010, 05:00 PM
#1
Thread Starter
New Member
NextChar Help Needed!
I am getting and error on line 26 with Size = keyboard.nextChar ();. What am I doing wrong? Thanks for your help and time.
Code:
/**
* @(#)MariosPizza.java
*
*
* @author
* @version 1.00 2010/1/24
*/
import java.util.Scanner;
public class MariosPizza {
public static void main(String args[]) {
char Size;
int TopComb;
float Price, GST, PST, StudentDiscount, SeniorDiscount;
boolean Senior, Student
Scanner keyboard = new Scanner (System.in);
System.out.println ("Welcome to Mario's Pizza")
System.out.println ("L = Large Pizza $9.99")
System.out.println ("M = Medium Pizza $7.99")
System.out.println ("S = Small Pizza $5.99")
System.out.println ("Please pick a basic size of pizza (S,M or L)")
Size = keyboard.nextChar ();
System.out.println ("You chose:" + Size)
switch (Size) {
case 'L':
case 'l': Price = 9.99f; break;
case 'M':
case 'm': Price = 7.99f; break;
case 'S':
case 's': Price = 5.99f; break;
default : System.out.println ("Not a valid choice!!");
}
System.out.println ("Choose your topping combination (1 to 5)")
System.out.println ("1 = Peperoni")
System.out.println ("2 = Combination (Peperoni, Green Peppers and Mushrooms")
System.out.println ("3 = Hawaiian (Ham and Pineapple)")
System.out.println ("4 = Meat Lovers (Sausage, Peperoni and Bacon)")
System.out.println ("5 = Vegetarian (Tomatoes, Olives and Green Peppers)")
TopComb = keyboard.nextInt ();
switch (TopComb) {
case '1' : Price = Price + 1; break;
case '2' : Price = Price + 3; break;
case '3' : Price = Price + 2; break;
case '4' : Price = Price + 3; break;
case '5' : Price = Price + 3; break;
default : System.out.println ("Not a valid choice!!");
}
}
}
-
Jan 25th, 2010, 07:29 PM
#2
Re: NextChar Help Needed!
You're missing several semicolons, nextChar is not a method of Scanner and your Price variable has not been initialized.
You could turn your Size variable into a string and then use Size.charAt(0) to grab the first character entered, or you could do System.in.read to grab character input.
Also, your final Price case is attempting to compare a char and a float, which will never give the result you're expecting.
-
Jan 25th, 2010, 09:11 PM
#3
Re: NextChar Help Needed!
To read a char use "char Size = (char) System.in.read();"
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|