diff --git a/pom.xml b/pom.xml index 1efac6c..e71048d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,10 @@ io.zipcoder MicroLabs-OOP-TooLargeTooSmall 1.0-SNAPSHOT + + 11 + 11 + \ No newline at end of file diff --git a/src/main/java/GuessingGame.java b/src/main/java/GuessingGame.java new file mode 100644 index 0000000..5567aad --- /dev/null +++ b/src/main/java/GuessingGame.java @@ -0,0 +1,36 @@ +import java.util.Scanner; +import java.lang.Math; +public class GuessingGame{ + public static void main(String[] args) { + + System.out.println("Guess a number!"); + + int answer = (int) (Math.random() * 100) + 1; + + int lives = 10; + + Scanner input = new Scanner(System.in); + System.out.println("Let's play a game...\nI'm thinking of a number between 1 and 100\n" + + "You have 10 tries before you lives run out!"); + System.out.print("What is your guess?"); + while (lives > 0) { + int guess = input.nextInt(); + if (guess == answer) { + System.out.println("You win this time..."); + break; + } + else if (guess > answer) { + System.out.println("Seems a bit high! \n Try again you have " + (lives - 1) + " tries remaining!"); + } + else { + System.out.println("Kind of a low ball! \n Try again you have " + (lives - 1) + " tries remaining!"); + } + lives--; + if (lives==0) { + System.out.println("It seems you're out of lives... BOOM!"); + } + + + } + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..9366625 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,41 @@ +import java.util.Scanner; + /** * Created by iyasuwatts on 10/17/17. */ public class Main { public static void main(String[] args){ - + + System.out.println("Guess a number!"); + + int answer = (int) (Math.random() * 100) + 1; + + int lives = 10; + + Scanner input = new Scanner(System.in); + System.out.println("Let's play a game...\nI'm thinking of a number between 1 and 100\n" + + "You have 10 tries before you lives run out!"); + System.out.print("What is your guess?"); + while (lives > 0) { + int guess = input.nextInt(); + if (guess == answer) { + System.out.println("You win this time..."); + break; + } + else if (guess > answer) { + System.out.println("Seems a bit high! \n Try again you have " + (lives - 1) + " tries remaining!"); + } + else { + System.out.println("Kind of a low ball! \n Try again you have " + (lives - 1) + " tries remaining!"); + } + lives--; + if (lives==0) { + System.out.println("It seems you're out of lives... BOOM!"); + } + + + } + } }