[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
skipping a step  XML
Forum Index » New to Java
Author Message
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

stdunbar

Newbie
[Avatar]

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
[WWW] [Yahoo!] [ICQ]
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.
stdunbar

Newbie
[Avatar]

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
[WWW] [Yahoo!] [ICQ]
spaztikmaverik

Newbie

Joined: 02/25/2010 21:11:44
Messages: 3
Offline

that worked, thank you very much.
 
Forum Index » New to Java
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle