Assignment #77 Sort Adventure 2: With a Loop
Code
/// Name: DeeJay Cerezo
/// Period: 7
/// Program Name: Adventure2
/// File Name: Adventure2.java
/// Date Finished: 2/20/2016
import java.util.Scanner;
import java.util.Scanner;
public class Adventure2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int nextroom = 1;
String choice = "";
while ( nextroom != 0 )
{
if ( nextroom == 1 )
{
System.out.println( "Room 1" );
System.out.print( "> You are in the bathroom. Do you /leave/ or /stay/?" );
choice = keyboard.nextLine();
if ( choice.equals("leave") )
nextroom = 2;
else if ( choice.equals("stay") )
nextroom = 3;
else
System.out.println( "ERROR." );
}
if ( nextroom == 2 )
{
System.out.println( "Room 2" );
System.out.print( "> You're in the master bedroom. Do you /sleep/ or /leave/ or go /back/?" );
choice = keyboard.nextLine();
if ( choice.equals("sleep") )
nextroom = 4;
else if ( choice.equals("leave") )
nextroom = 5;
else if ( choice.equals("back") )
nextroom = 1;
if ( nextroom == 4 )
{
System.out.println( "Still Room 2" );
System.out.print( "> You fall into eternal slumber and die." );
}
if ( nextroom == 5 )
{
System.out.println( "Room 4" );
System.out.print( "> You go out to the outside world." );
}
}
if ( nextroom == 3 )
{
System.out.println( "Room 3" );
System.out.print( ">You stay in the bathroom. Do you /leave/ or /stay/ longer or go /back/ in time to when you were fist asked whether to leave or stay? " );
choice = keyboard.nextLine();
if ( choice.equals("leave") )
nextroom = 2;
else if ( choice.equals("stay") )
nextroom = 6;
else if ( choice.equals("back") )
nextroom = 1;
else
System.out.println( "ERROR." );
}
if ( nextroom == 6 )
{
System.out.println( "Room 6" );
System.out.print( "> You stay and pass out from toxic fumes." );
}
}
System.out.println( "\nEND." );
}
}
Picture of the output