Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class GuessingGame here.
- *
- * @Arjun Bhamra
- * @9/6/19
- */
- import java.util.*;
- import java.lang.String;
- public class GuessingGame
- {
- /**
- * Constructor for objects of class GuessingGame
- */
- public static void main(String[] args){
- game();
- Scanner sc = new Scanner(System.in);
- System.out.println("Press 1 to try again. Press 2 to quit.");
- int choice = 1;
- while(choice==1){
- choice=sc.nextInt();
- System.out.println("Press 1 to try again. Press 2 to quit.");
- if(choice==1){
- game();
- } else if(choice==2) {
- System.out.println("Thank you for playing!");
- }
- //figure out how to make it so that based on the response,
- //it will actually work and stop the program. maybe ask
- //the upperclassmen.
- }
- }
- public static void game(){
- int max = 10;
- int min = 1;
- int randomNum = (int)(Math.random() * ((max-min)+1))+min;
- int count = 3;
- while(count>0){
- Scanner initialGuess = new Scanner(System.in);
- System.out.println("What is your guess? Make sure it is between 1 and 10");
- if(initialGuess.hasNextInt()){
- int guess = initialGuess.nextInt();
- if(guess<max && guess>=min){
- if (guess==randomNum){
- System.out.println("Winner");
- count=0;
- } else {
- System.out.println("Sorry, try again");
- count--;
- }
- } else {
- System.out.println("You inputted something incorrect! Try again.");
- }
- } else {
- System.out.println("You inputted something incorrect! Try again.");
- }
- }
- if(count==0){
- System.out.println("The game has ended.");
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement