Skip to content

Commit 8474994

Browse files
committed
works
1 parent 8526dfb commit 8474994

3 files changed

Lines changed: 16 additions & 30 deletions

File tree

app/build.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/*
2-
* This file was generated by the Gradle 'init' task.
3-
*
4-
* This generated file contains a sample Java application project to get you started.
5-
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.14.2/userguide/building_java_projects.html in the Gradle documentation.
6-
* This project uses @Incubating APIs which are subject to change.
7-
*/
8-
91
plugins {
102
// Apply the application plugin to add support for building a CLI application in Java.
113
id 'application'
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.github.project516.NumberGuessingGame;
22

3-
import java.util.Scanner;
4-
53
public class Main {
64

75
public static void main(String[] args) {
86

7+
int numOfGuesses = 0;
8+
99
ScannerHelper scan = new ScannerHelper();
10-
SystemInfo systemInfo = new SystemInfo();
10+
SystemInfo sysInfo = new SystemInfo();
1111
RandomNumber ranNumber = new RandomNumber();
1212

1313
try {
@@ -26,23 +26,25 @@ public static void main(String[] args) {
2626

2727
System.out.print("Guess a number: ");
2828
int guess = scan.userGuess();
29-
System.out.println(guess);
30-
scan.close();
29+
if (guess > number) {
30+
System.out.println("You guessed to much!");
31+
} else if (guess < number) {
32+
System.out.println("You guessed to little!");
33+
} else {
34+
numOfGuesses++;
35+
break;
36+
}
37+
numOfGuesses++;
3138
}
3239

33-
}
34-
35-
catch (Exception e) {
40+
System.out.println("Took you " + numOfGuesses + " guesses!");
3641

37-
e.printStackTrace();
38-
}
42+
} catch (Exception e) {
3943

40-
41-
finally {
44+
e.printStackTrace();
45+
} finally {
4246

4347
scan.close();
4448
}
45-
4649
}
47-
4850
}

settings.gradle

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
/*
2-
* This file was generated by the Gradle 'init' task.
3-
*
4-
* The settings file is used to specify which projects to include in your build.
5-
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.14.2/userguide/multi_project_builds.html in the Gradle documentation.
6-
* This project uses @Incubating APIs which are subject to change.
7-
*/
8-
91
plugins {
102
// Apply the foojay-resolver plugin to allow automatic download of JDKs
113
id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'

0 commit comments

Comments
 (0)