| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 02/25/2010 21:16:49
|
spaztikmaverik
Newbie
Joined: 02/25/2010 21:11:44
Messages: 3
Offline
|
when i run the program it will not allow me to enter 'yes' or 'no' in response. it runs the "Please enter...." line, gives a space, and moves on to the next section of code in the program. (not shown)
edit: I decided to just put the whole method on here because when i tested the piece from before it worked fine.
public static void userInterface()
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter 'Avatar', 'The Blind Side', or 'Up'.\n");
String movie = scan.nextLine();
if(!movie.equals("Avatar") ^ !movie.equals("The Blind Side") ^ !movie.equals("Up"))
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Please enter the month you wish to see the movie in as an integer.");
System.out.println("('3' for March, '4' for April, '5' for May)\n");
int month = scan.nextInt();
if(month != 3 ^ month != 4 ^ month != 5)
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Please enter the date you wish to view the movie on.\n");
int date = scan.nextInt();
if(!isValidDate(month, date))
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Please enter 'yes' or 'no' if you want to watch the matinee or not.\n");
String matineeOrNot = scan.nextLine();
boolean isMatinee;
if(matineeOrNot.equals("yes"))
{
isMatinee = true;
}
else
{
isMatinee = false;
}
if(!matineeOrNot.equals("yes") && !matineeOrNot.equals("no"))
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Please enter the number of adult tickets you want.\n");
System.out.println("('0' if none)");
int adultTickets = scan.nextInt();
if(adultTickets < 0)
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Please enter the number of student tickets you want.");
System.out.println("('0' if none)\n");
int studentTickets = scan.nextInt();
if(studentTickets < 0)
{
System.out.println("\nInvalid input");
System.exit(1);
}
System.out.println("\n");
System.out.println("Your tickets cost $" + getCost(movie,month,date,isMatinee,adultTickets,studentTickets));
}
This message was edited 1 time. Last update was at 02/25/2010 21:53:09
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 02/26/2010 08:24:58
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
Try to use just next() to read the String.
|
Thanks for using the forums at hotjoe.com |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 02/26/2010 09:07:20
|
spaztikmaverik
Newbie
Joined: 02/25/2010 21:11:44
Messages: 3
Offline
|
stdunbar wrote:Try to use just next() to read the String.
would you mind elaborating? i just started java a few weeks ago.
|
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 02/26/2010 09:12:56
|
stdunbar
Newbie
![[Avatar]](/images/avatar/a87ff679a2f3e71d9181a67b7542122c.png)
Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline
|
Sure - in your current code you're doing:
Instead, try:
I always have problems with the nextLine method reading and behaving differently than I want.
|
Thanks for using the forums at hotjoe.com |
|
|
 |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 02/26/2010 11:33:45
|
spaztikmaverik
Newbie
Joined: 02/25/2010 21:11:44
Messages: 3
Offline
|
that worked, thank you very much.
|
|
|
 |
|
|