Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. /**
  2. * Write a description of class GuessingGame here.
  3. *
  4. * @Arjun Bhamra
  5. * @9/6/19
  6. */
  7. import java.util.*;
  8. import java.lang.String;
  9. public class GuessingGame
  10. {
  11. /**
  12. * Constructor for objects of class GuessingGame
  13. */
  14. public static void main(String[] args){
  15. game();
  16. Scanner sc = new Scanner(System.in);
  17. System.out.println("Press 1 to try again. Press 2 to quit.");
  18. int choice = 1;
  19.  
  20. while(choice==1){
  21. choice=sc.nextInt();
  22. System.out.println("Press 1 to try again. Press 2 to quit.");
  23. if(choice==1){
  24. game();
  25. } else if(choice==2) {
  26. System.out.println("Thank you for playing!");
  27. }
  28. //figure out how to make it so that based on the response,
  29. //it will actually work and stop the program. maybe ask
  30. //the upperclassmen.
  31. }
  32. }
  33.  
  34. public static void game(){
  35. int max = 10;
  36. int min = 1;
  37. int randomNum = (int)(Math.random() * ((max-min)+1))+min;
  38. int count = 3;
  39.  
  40. while(count>0){
  41. Scanner initialGuess = new Scanner(System.in);
  42. System.out.println("What is your guess? Make sure it is between 1 and 10");
  43.  
  44. if(initialGuess.hasNextInt()){
  45. int guess = initialGuess.nextInt();
  46. if(guess<max && guess>=min){
  47. if (guess==randomNum){
  48. System.out.println("Winner");
  49. count=0;
  50. } else {
  51. System.out.println("Sorry, try again");
  52. count--;
  53. }
  54. } else {
  55. System.out.println("You inputted something incorrect! Try again.");
  56. }
  57. } else {
  58. System.out.println("You inputted something incorrect! Try again.");
  59. }
  60. }
  61. if(count==0){
  62. System.out.println("The game has ended.");
  63. }
  64.  
  65. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement