From 36b8cf11111df56a6f421bff6836d49910cc845a Mon Sep 17 00:00:00 2001 From: nstine77 Date: Sun, 4 Feb 2024 15:42:21 -0800 Subject: [PATCH] I've begun creating an extra Class page and calling it "ScratchPaper. I deleted it, but if in my noobism it still shows up, please let me know, so I can learn how to not do it that way." --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ src/GuessStarter.java | 31 +++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index cf9abe6..cbbff6a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/GuessStarter.java b/src/GuessStarter.java index 64984df..b4403ee 100644 --- a/src/GuessStarter.java +++ b/src/GuessStarter.java @@ -1,15 +1,26 @@ import java.util.Random; +import java.util.Scanner; -/** - * Starter code for the "Guess My Number" exercise. - */ public class GuessStarter { - public static void main(String[] args) { - // pick a random number - Random random = new Random(); - int number = random.nextInt(100) + 1; - System.out.println(number); + Random rand = new Random(); + Scanner scanner = new Scanner(System.in); + int number = rand.nextInt(100) + 1; + System.out.println("Guess the random whole number between 1 and 100: "); + int guessResult = scanner.nextInt(); + System.out.println("You said: " + guessResult); + System.out.println("The number I was thinking of is: " + number); + if (number == guessResult) { + System.out.println("Wow, Great guess! You got it right!");} + else { + System.out.print("Unfortunately, you were off by; " + (guessResult - number)); + } + /* For the sake of testing my code, I tried entering 5000 as the guess. While the script + found its number within the defined parameters, it still calculated the difference + from what I entered as a guess result of 5000. + Further experimenting, I tried a number with a decimal and partial number, and + the program generated a string of error results. I'm having difficulty with remembering things, + by Grabthar's Hammer, I WILL try things and learn! + */ } - -} +} \ No newline at end of file