Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. Scanner scan = new Scanner(System.in);
  2.  
  3. System.out.println("Would you like to play a game called Threes? Y/N");
  4. String answer = scan.nextLine(); //Simple yes or no
  5.  
  6. if (answer.contains("Y") || (answer.contains("y"))) {
  7. System.out.println("OK, want to know how it works? Y/N");
  8. String answer2 = scan.nextLine();
  9. if (answer2.contains("n") || (answer2.contains("N"))) {
  10. System.out.println("OK, Enter a single number.");
  11.  
  12. int mistake = 0; //Used as a counter for number of division mistakes made
  13. int numstart = scan.nextInt(); //First number input
  14. int current = numstart; //Current number displayed - starts as the first number
  15.  
  16. System.out.println("Enter 1 or -1 if you're adding or subtracting, and 0 to divide.");
  17. System.out.println(numstart); //Displays first number input
  18. int input = scan.nextInt(); //First function performed by user
  19.  
  20. while (current != 1) { //The game will run until the number '1' is reached
  21. if (input == 1) { //If '1' is input, add one to the number, and display new number
  22. current++;
  23. System.out.println(current);
  24. input = scan.nextInt();
  25. }
  26. if (input == -1) { //If '-1' is input, subtract one from the number, and display new number
  27. current--;
  28. System.out.println(current);
  29. input = scan.nextInt();
  30. }
  31. if (input == 0) { //If '0' is input, try to divide
  32. if (current % 3 != 0 && current != 1) { //If you can't divide by three, try again
  33. System.out.println("Try again.");
  34. mistake++;
  35. input = scan.nextInt();
  36. }
  37. if (current % 3 == 0) { //If you can divide, do it and display new number
  38. current = current / 3;
  39. System.out.println(current);
  40. input = scan.nextInt();
  41. }
  42. }
  43. if (input == 69 || input == 666) //Cheat code! If you input 69 or 666, you automatically win
  44. break;
  45. if (((input > 1) && (input != 69) && (input != 666)) || input < -1) { //If input is not valid, try again and display error
  46. System.out.println("Error - wrong input.");
  47. input = scan.nextInt();
  48. }
  49. }
  50. System.out.println("You Win! Mistakes: " + mistake + "n"); //Will display a win condition, and amount of division errors
  51. System.out.println("Thank you for playing Threes n - Chris Burbach");
  52. }
  53. System.out.println("Credits? Y/N");
  54. String credits = scan.nextLine();
  55.  
  56. if(credits.contains("Y")||credits.contains("y"))
  57. {
  58. System.out.println("n***********************************************************************");
  59. System.out.println("*Threes: a game of dividing by three - inspired by my boredom in class*");
  60. System.out.println("***********************************************************************");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement