From 54775a5b8a9a76c356e4058eb3576be871d06176 Mon Sep 17 00:00:00 2001 From: Amy Gill Date: Thu, 8 Feb 2018 07:38:46 -0500 Subject: [PATCH 1/4] Very very very happy --- src/main/java/Main.java | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..724c467 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,51 @@ +import java.util.Scanner; +import java.util.Random; + /** * Created by iyasuwatts on 10/17/17. */ public class Main { - public static void main(String[] args){ - + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("Please enter a number between 1 and 10."); + + Random randomNum = new Random(); + + int desiredInt = randomNum.nextInt(10) + 1; + int count = 0; + + while (true) { + int userResponse = input.nextInt(); + count++; + if (userResponse > desiredInt) { + System.out.println("Sorry. Your guess is too great."); + } else if (userResponse < desiredInt) { + System.out.println("Sorry. Your guess is not large enough."); + } else if (userResponse == desiredInt) { + System.out.println("Congratulations! You just did something an untrained monkey could do.... " + + "But don't feel too badly. The monkey totally got it right on the first try and it" + + " only took you " + count + " tries."); + } + + } + + /* + for (int i = 0; i < response; i++){ + + if (response > desiredInt) { + System.out.println("Sorry. Your answer is too great."); + } else if (response < desiredInt){ + System.out.println("Sorry. Your answer is not large enough."); + } else if (response == desiredInt){ + System.out.println("Congratulations! You just did something a monkey could do...."); + } + count += i; + } + + + + System.out.println(count); +*/ } } From fcbebf2c4186ac87c543bec9c415c4e59984b6f5 Mon Sep 17 00:00:00 2001 From: Amy Gill Date: Thu, 8 Feb 2018 12:21:14 -0500 Subject: [PATCH 2/4] thanks f:) --- src/main/java/Main.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 724c467..8f6664a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -15,7 +15,9 @@ public static void main(String[] args) { int desiredInt = randomNum.nextInt(10) + 1; int count = 0; - while (true) { + boolean flag = false; + + while (!flag) { int userResponse = input.nextInt(); count++; if (userResponse > desiredInt) { @@ -26,6 +28,7 @@ public static void main(String[] args) { System.out.println("Congratulations! You just did something an untrained monkey could do.... " + "But don't feel too badly. The monkey totally got it right on the first try and it" + " only took you " + count + " tries."); + flag = true; } } From 86817d66a7491cace9f5885257447c741be96b8a Mon Sep 17 00:00:00 2001 From: Amy Gill Date: Sun, 18 Feb 2018 18:53:12 -0500 Subject: [PATCH 3/4] redone. better understanding of java util Random class. still working on the details loop --- src/main/java/Main.java | 50 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 8f6664a..d4ac2bf 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,6 +4,53 @@ /** * Created by iyasuwatts on 10/17/17. */ + + + +public class Main { + public static void main(String[] args) { + Scanner input = new Scanner(System.in); + System.out.println("Please enter a number between 1 and 10."); + + Random generator = new Random(); + int min = 1; + int max = 10; + int randomlyGeneratedNumber = min + generator.nextInt(max); + + boolean didTheyGuessCorrectly = false; + int count = 0; + + while (!didTheyGuessCorrectly) { + int usersGuess = input.nextInt(); + count++; + if (usersGuess > randomlyGeneratedNumber) { + System.out.println("Sorry. Your guess was too big. Please try again."); + } else if (usersGuess < randomlyGeneratedNumber) { + System.out.println("Sorry. Your guess was too small. Please try again."); + } else if (usersGuess == randomlyGeneratedNumber){ + System.out.println("Congratulations! You are correct. It took you exactly " + count + " tries." + + "\nHave a nice day."); + didTheyGuessCorrectly = true; + } + } + } +} + + + + + + + + + + + + + + + +/* public class Main { public static void main(String[] args) { @@ -50,5 +97,4 @@ public static void main(String[] args) { System.out.println(count); */ - } -} + From 951d389dd5c9cb8bc350abcb928fe1b789a2c989 Mon Sep 17 00:00:00 2001 From: Amy Gill Date: Sun, 18 Feb 2018 19:12:42 -0500 Subject: [PATCH 4/4] removed comments, code is the same --- src/main/java/Main.java | 63 ----------------------------------------- 1 file changed, 63 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d4ac2bf..bc299e9 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -35,66 +35,3 @@ public static void main(String[] args) { } } } - - - - - - - - - - - - - - - -/* -public class Main { - - public static void main(String[] args) { - Scanner input = new Scanner(System.in); - System.out.println("Please enter a number between 1 and 10."); - - Random randomNum = new Random(); - - int desiredInt = randomNum.nextInt(10) + 1; - int count = 0; - - boolean flag = false; - - while (!flag) { - int userResponse = input.nextInt(); - count++; - if (userResponse > desiredInt) { - System.out.println("Sorry. Your guess is too great."); - } else if (userResponse < desiredInt) { - System.out.println("Sorry. Your guess is not large enough."); - } else if (userResponse == desiredInt) { - System.out.println("Congratulations! You just did something an untrained monkey could do.... " + - "But don't feel too badly. The monkey totally got it right on the first try and it" + - " only took you " + count + " tries."); - flag = true; - } - - } - - /* - for (int i = 0; i < response; i++){ - - if (response > desiredInt) { - System.out.println("Sorry. Your answer is too great."); - } else if (response < desiredInt){ - System.out.println("Sorry. Your answer is not large enough."); - } else if (response == desiredInt){ - System.out.println("Congratulations! You just did something a monkey could do...."); - } - count += i; - } - - - - System.out.println(count); -*/ -