Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<groupId>io.zipcoder</groupId>
<artifactId>MicroLabs-OOP-TooLargeTooSmall</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>


</project>
39 changes: 33 additions & 6 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
/**
* Created by iyasuwatts on 10/17/17.
*/
import java.util.HashSet;
import java.util.Scanner;


public class Main {
public static void main(String[] args) {
int min = 0; //minimum number for range of generation
int max = 50; //maximum number for range of generation
int numGuesses = 0; //this will track the number of user's guesses
int guess = 0; //this will track the value of the user's guesses
int answer = (int) Math.floor(Math.random() * (max - min + 1) + min); //randomly generate number between min and max
//int answer = 5; //controlled answer value for testing
HashSet<Integer> guessSet = new HashSet<Integer>(); //set for storing guesses

while (guess != answer) { //loop will continue until user guesses the correct value

Scanner input = new Scanner(System.in); //initializes scanner
System.out.println("Guess the number"); //prompts user to enter their guess
guess = input.nextInt(); //stores user input into int guess
guessSet.add(guess); //adds guess as entry into set

public static void main(String[] args){

if (guess < min || guess > max) { //checks if guess is below/above the expected range
System.out.println("You guess over or below the acceptable range of: " + min + " to " + max); //informs user they've guessed lower/higher than expected range
}
else if (guess > answer) { //checks if guess is higher than the answer
System.out.println("You guessed too high."); //informs user they've guessed too high
}
else if (guess < answer) { //checks if guess is less than the answer
System.out.println("You guessed too low."); //informs user they've guessed too low
}
else {
System.out.println("Congrats. You guessed " + answer + " and it only took you " + guessSet.size() + " tries.");
}
}
}
}
}