From 4e9b65eb84d17dacef21617e5c0c64018da71683 Mon Sep 17 00:00:00 2001 From: CreeperKelten Date: Sun, 4 Feb 2024 16:12:31 -0800 Subject: [PATCH] Kelten Stowe --- .idea/misc.xml | 2 +- .idea/vcs.xml | 6 ++++++ src/GuessStarter.java | 25 ++++++++++++++++++++----- 3 files changed, 27 insertions(+), 6 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..36b61f5 100644 --- a/src/GuessStarter.java +++ b/src/GuessStarter.java @@ -1,15 +1,30 @@ import java.util.Random; - +import java.util.Scanner; /** - * Starter code for the "Guess My Number" exercise. + * Editors note here I had a lot of fun with this just thought you would like my opinion on this and thinking outside the box + * Author Kelten Stowe + * Author Trevor Hartman + * Date 2/4/2024 + * Starter code for the "Guess My Number" exercise. */ -public class GuessStarter { +import java.util.Random; +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); + // prompt the user for a guess + System.out.print("Guess the number (between 1 and 100): "); + // use Scanner to read user input as an integer + Scanner scanner = new Scanner(System.in); + int Guess = scanner.nextInt(); + // display the user's guess + System.out.println("Your guess: " + Guess); + // compute and display the difference between user's guess and the generated number + int difference = Math.abs(number - Guess); + System.out.println("The difference between the generated number and your guess is: " + difference); + // close the scanner + scanner.close(); } - }