Advertisement
krluce

TerminalAdventure01

Aug 18th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. /* Terminal Adventure 01 created by Kristen Luce */
  2. /* Please do not redistribute this code unless you are using it as a teaching tool or are referencing it */
  3.  
  4. //Import scanner
  5. import java.util.Scanner;
  6.  
  7. //begin the main (and possibly only) class
  8. public class TerminalAdventure01 {
  9.  
  10. //set up scanner (imported from above)
  11. static Scanner input = new Scanner(System.in);
  12.    
  13. //begin main (holds <almost> all functional code)
  14.     public static void main(String[] args) {
  15. // Create the first couple of lines for when application is executed
  16.         System.out.println("Hello friend, what is your name?");
  17.         System.out.print("Please type your name: ");
  18. // Allow the user to input their name
  19.         String name = input.nextLine();
  20. // Call the user by their selected name
  21.         System.out.println("Ah, so your name is " + name + ", it's nice to meet you!");
  22.         System.out.println("Anyhow, today is a very important day. Today is the day that you emark on a TERMINAL ADVENTURE!!");
  23.         System.out.println("First, I need to know if you're human... are you a human? true or false. Please note that selecting false will exit the system.");
  24.         System.out.print("Please type your answer: ");
  25. // Create a boolean scanner called humanAnswer that only accepts the words "true" or "false"
  26.         boolean humanAnswer = input.nextBoolean();
  27. // An if statement that is run if the user types "true"
  28.         if (humanAnswer ==  true)
  29.         System.out.println("Good job, I believe you are very much human, " + name + "!");
  30. // An else if statement to fall back on in case the user says "false", exits program if run
  31.         else if (humanAnswer == false)
  32.         System.exit(0);
  33.         System.out.print("Oh, I forgot to mention something. You cannot beat this TERMINAL ADVENTURE,");
  34.         System.out.println(" you can only explore and find new things to aid you.");
  35. // Ask the user if they'd like to continue, warns user that the program will exit when 2 is typed.
  36.         System.out.print("Will you continue? Type 1 for yes and 2 for no (typing 2 will force you to exit): ");
  37. // Set up questYes and questNo and link them to "1" and "2"
  38.         int questYes;
  39.         int questNo;
  40.         questYes = 1;
  41.         questNo = 2;
  42. // Have user input selection
  43.         int questDecision = input.nextInt();
  44. // Very similar to the before if and else if statements
  45.         if (questDecision == 1)
  46.         System.out.println("Hey, " + name + ", I think you're ready.");
  47.         else if (questDecision == 2)
  48.         System.exit(0);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement