| 3 | import java.util.Scanner; |
| 4 | |
| 5 | public class GuessTheNumber { |
| 6 | private int guesses = 10; |
| 7 | private int warning = 4; |
| 8 | private int guessedNo; |
| 9 | private int[] alreadyTold = new int[10]; |
| 10 | private int specialWarning = 1; |
| 11 | int index = 0; |
| 12 | int rng = 20; |
| 13 | |
| 14 | public Scanner inputInt(){ |
| 15 | System.out.print("\nEnter Your Guess: "); |
| 16 | return new Scanner(System.in); |
| 17 | } |
| 18 | |
| 19 | public boolean isValid(Scanner inp){ |
| 20 | return inp.hasNextInt(); |
| 21 | } |
| 22 | |
| 23 | public int generateRand(int range){ |
| 24 | Random rand = new Random(); |
| 25 | return rand.nextInt(range); |
| 26 | } |
| 27 | public void setAlreadyTold(int guess){ |
| 28 | this.alreadyTold[this.index] = guess; |
| 29 | this.index++; |
| 30 | } |
| 31 | |
| 32 | public boolean isAlreadyTold(int guess){ |
| 33 | for(int i = 0; i < 10; i++){ |
| 34 | if(guess == this.alreadyTold[i]){ |
| 35 | return true; |
| 36 | } |
| 37 | } |
| 38 | return false; |
| 39 | } |
| 40 | public void printGuessed(){ |
| 41 | for(int i = 0; i < 10; i ++){ |
| 42 | if(alreadyTold[i] != -1) |
| 43 | System.out.print(alreadyTold[i] + " "); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | public void setGuessedToNull(){ |
| 48 | for(int i = 0; i < 10; i ++){ |
| 49 | alreadyTold[i] = -1; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | public void play(){ |
| 54 | setGuessedToNull(); |
| 55 | int secretNum = generateRand(rng); |
| 56 | System.out.println("I am Thinking of a word between 0-"+ rng + "."); |
| 57 | Scanner scanGuess; |
| 58 | int guess; |
| 59 | boolean flag = true; |
| 60 | do{ |
| 61 | System.out.print("Remaining guesses: "+this.guesses+"\nRemaining warnings: "+this.warning + "\nGuessed Numbers: "); printGuessed(); |
| 62 | scanGuess = inputInt(); |
nothing calls this directly
no outgoing calls
no test coverage detected