Skip to content

Commit 9bec25d

Browse files
Add files via upload
1 parent a5d3f71 commit 9bec25d

File tree

13 files changed

+193
-0
lines changed

13 files changed

+193
-0
lines changed

Guess The Number Game/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>br.com.exemplo</groupId>
6+
<artifactId>meu-projeto</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
9+
<properties>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.junit.jupiter</groupId>
17+
<artifactId>junit-jupiter</artifactId>
18+
<version>5.10.2</version>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
22+
23+
<build>
24+
<plugins>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-surefire-plugin</artifactId>
28+
<version>3.2.5</version>
29+
</plugin>
30+
</plugins>
31+
</build>
32+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package learningspace.swtest.examples;
2+
3+
public class GameLogic {
4+
public String checkGuess(int guess, int correctNumber) {
5+
if (guess == correctNumber) {
6+
return "Correct!";
7+
} else if (guess < correctNumber) {
8+
return "Too low!";
9+
} else {
10+
return "Too high!";
11+
}
12+
}
13+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import javafx.application.Application;
2+
import javafx.scene.Scene;
3+
import javafx.scene.control.Label;
4+
import javafx.scene.control.TextField;
5+
import javafx.scene.layout.VBox;
6+
import javafx.stage.Stage;
7+
8+
public class GuessTheNumberGame extends Application {
9+
private int targetNumber = (int) (Math.random() * 100) + 1;
10+
private int numberOfTries = 0;
11+
12+
public static void main(String[] args) {
13+
launch(args);
14+
}
15+
16+
@Override
17+
public void start(Stage primaryStage) {
18+
primaryStage.setTitle("Guess the Number Game");
19+
20+
Label titleLabel = new Label("Guess the Number (1-100)");
21+
TextField guessInput = new TextField();
22+
guessInput.setId("guessInput"); // ID adicionado
23+
Label messageLabel = new Label();
24+
messageLabel.setId("messageLabel"); // ID adicionado
25+
VBox vbox = new VBox(titleLabel, guessInput, messageLabel);
26+
27+
guessInput.setOnAction(e -> {
28+
try {
29+
int userGuess = Integer.parseInt(guessInput.getText());
30+
numberOfTries++;
31+
if (userGuess < targetNumber) {
32+
messageLabel.setText("Try higher.");
33+
} else if (userGuess > targetNumber) {
34+
messageLabel.setText("Try lower.");
35+
} else {
36+
messageLabel.setText("Congratulations! You guessed the number in " + numberOfTries + " tries.");
37+
}
38+
guessInput.clear();
39+
} catch (NumberFormatException ex) {
40+
messageLabel.setText("Invalid input. Enter a number.");
41+
}
42+
});
43+
44+
Scene scene = new Scene(vbox, 300, 150);
45+
primaryStage.setScene(scene);
46+
primaryStage.show();
47+
}
48+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import learningspace.swtest.examples.GameLogic;
2+
import org.junit.jupiter.api.Test;
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
public class GameLogicTest {
6+
7+
@Test
8+
void testCorrectGuess() {
9+
GameLogic logic = new GameLogic();
10+
assertEquals("Correct!", logic.checkGuess(7, 7));
11+
}
12+
13+
@Test
14+
void testTooLow() {
15+
GameLogic logic = new GameLogic();
16+
assertEquals("Too low!", logic.checkGuess(5, 7));
17+
}
18+
19+
@Test
20+
void testTooHigh() {
21+
GameLogic logic = new GameLogic();
22+
assertEquals("Too high!", logic.checkGuess(9, 7));
23+
}
24+
}
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GuessTheNumberGame.class
2+
learningspace\swtest\examples\GameLogic.class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GameLogic.java
2+
C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GuessTheNumberGame.java
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GameLogicTest.class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
C:\Users\anell\Downloads\trabalho\Guess the number\src\test\java\learningspace\swtest\examples\GameLogicTest.java
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-------------------------------------------------------------------------------
2+
Test set: GameLogicTest
3+
-------------------------------------------------------------------------------
4+
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.082 s -- in GameLogicTest
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd" version="3.0" name="GameLogicTest" time="0.082" tests="3" errors="0" skipped="0" failures="0">
3+
<properties>
4+
<property name="sun.desktop" value="windows"/>
5+
<property name="awt.toolkit" value="sun.awt.windows.WToolkit"/>
6+
<property name="file.encoding.pkg" value="sun.io"/>
7+
<property name="java.specification.version" value="1.8"/>
8+
<property name="sun.cpu.isalist" value="amd64"/>
9+
<property name="sun.jnu.encoding" value="Cp1252"/>
10+
<property name="java.class.path" value="C:\Users\anell\Downloads\trabalho\Guess the number\target\test-classes;C:\Users\anell\Downloads\trabalho\Guess the number\target\classes;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter\5.10.2\junit-jupiter-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.10.2\junit-jupiter-api-5.10.2.jar;C:\Users\anell\.m2\repository\org\opentest4j\opentest4j\1.3.0\opentest4j-1.3.0.jar;C:\Users\anell\.m2\repository\org\junit\platform\junit-platform-commons\1.10.2\junit-platform-commons-1.10.2.jar;C:\Users\anell\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.10.2\junit-jupiter-params-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.10.2\junit-jupiter-engine-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\platform\junit-platform-engine\1.10.2\junit-platform-engine-1.10.2.jar;"/>
11+
<property name="java.vm.vendor" value="Oracle Corporation"/>
12+
<property name="sun.arch.data.model" value="64"/>
13+
<property name="user.variant" value=""/>
14+
<property name="java.vendor.url" value="http://java.oracle.com/"/>
15+
<property name="user.timezone" value="America/Sao_Paulo"/>
16+
<property name="java.vm.specification.version" value="1.8"/>
17+
<property name="os.name" value="Windows 10"/>
18+
<property name="user.country" value="BR"/>
19+
<property name="sun.java.launcher" value="SUN_STANDARD"/>
20+
<property name="sun.boot.library.path" value="C:\Program Files\Java\jdk1.8.0_202\jre\bin"/>
21+
<property name="sun.java.command" value="C:\Users\anell\AppData\Local\Temp\surefire2485458507096907854\surefirebooter-20250501200944218_3.jar C:\Users\anell\AppData\Local\Temp\surefire2485458507096907854 2025-05-01T20-09-43_006-jvmRun1 surefire-20250501200944218_1tmp surefire_0-20250501200944218_2tmp"/>
22+
<property name="surefire.test.class.path" value="C:\Users\anell\Downloads\trabalho\Guess the number\target\test-classes;C:\Users\anell\Downloads\trabalho\Guess the number\target\classes;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter\5.10.2\junit-jupiter-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.10.2\junit-jupiter-api-5.10.2.jar;C:\Users\anell\.m2\repository\org\opentest4j\opentest4j\1.3.0\opentest4j-1.3.0.jar;C:\Users\anell\.m2\repository\org\junit\platform\junit-platform-commons\1.10.2\junit-platform-commons-1.10.2.jar;C:\Users\anell\.m2\repository\org\apiguardian\apiguardian-api\1.1.2\apiguardian-api-1.1.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.10.2\junit-jupiter-params-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.10.2\junit-jupiter-engine-5.10.2.jar;C:\Users\anell\.m2\repository\org\junit\platform\junit-platform-engine\1.10.2\junit-platform-engine-1.10.2.jar;"/>
23+
<property name="sun.cpu.endian" value="little"/>
24+
<property name="user.home" value="C:\Users\anell"/>
25+
<property name="user.language" value="pt"/>
26+
<property name="java.specification.vendor" value="Oracle Corporation"/>
27+
<property name="java.home" value="C:\Program Files\Java\jdk1.8.0_202\jre"/>
28+
<property name="basedir" value="C:\Users\anell\Downloads\trabalho\Guess the number"/>
29+
<property name="file.separator" value="\"/>
30+
<property name="line.separator" value="&#10;"/>
31+
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
32+
<property name="java.specification.name" value="Java Platform API Specification"/>
33+
<property name="java.awt.graphicsenv" value="sun.awt.Win32GraphicsEnvironment"/>
34+
<property name="surefire.real.class.path" value="C:\Users\anell\AppData\Local\Temp\surefire2485458507096907854\surefirebooter-20250501200944218_3.jar"/>
35+
<property name="sun.boot.class.path" value="C:\Program Files\Java\jdk1.8.0_202\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\rt.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_202\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_202\jre\classes"/>
36+
<property name="user.script" value=""/>
37+
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
38+
<property name="java.runtime.version" value="1.8.0_202-b08"/>
39+
<property name="user.name" value="anell"/>
40+
<property name="path.separator" value=";"/>
41+
<property name="os.version" value="10.0"/>
42+
<property name="java.endorsed.dirs" value="C:\Program Files\Java\jdk1.8.0_202\jre\lib\endorsed"/>
43+
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
44+
<property name="file.encoding" value="Cp1252"/>
45+
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM"/>
46+
<property name="localRepository" value="C:\Users\anell\.m2\repository"/>
47+
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/"/>
48+
<property name="java.io.tmpdir" value="C:\Users\anell\AppData\Local\Temp\"/>
49+
<property name="java.version" value="1.8.0_202"/>
50+
<property name="user.dir" value="C:\Users\anell\Downloads\trabalho\Guess the number"/>
51+
<property name="os.arch" value="amd64"/>
52+
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
53+
<property name="java.awt.printerjob" value="sun.awt.windows.WPrinterJob"/>
54+
<property name="sun.os.patch.level" value=""/>
55+
<property name="java.library.path" value="C:\Program Files\Java\jdk1.8.0_202\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\MinGW\bin;C:\Program Files\Apache\Maven\apache-maven-3.9.9\bin;C:\Program Files\Java\jdk1.8.0_202\bin;C:\Users\anell\AppData\Local\Programs\Python\Python313\Scripts\;C:\Users\anell\AppData\Local\Programs\Python\Python313\;C:\Users\anell\AppData\Local\Programs\Python\Launcher\;C:\Users\anell\AppData\Local\Microsoft\WindowsApps;C:\MinGW\bin\g++;C:\Users\anell\AppData\Local\Programs\Microsoft VS Code\bin\gcc;C:\Users\anell\AppData\Local\Programs\Microsoft VS Code\bin;C:\src\flutter\bin;C:\Users\anell\AppData\Roaming\npm;C:\Program Files\Apache\Maven\apache-maven-3.9.9\bin;;."/>
56+
<property name="java.vm.info" value="mixed mode"/>
57+
<property name="java.vendor" value="Oracle Corporation"/>
58+
<property name="java.vm.version" value="25.202-b08"/>
59+
<property name="java.ext.dirs" value="C:\Program Files\Java\jdk1.8.0_202\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext"/>
60+
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
61+
<property name="java.class.version" value="52.0"/>
62+
</properties>
63+
<testcase name="testTooHigh" classname="GameLogicTest" time="0.034"/>
64+
<testcase name="testCorrectGuess" classname="GameLogicTest" time="0.0"/>
65+
<testcase name="testTooLow" classname="GameLogicTest" time="0.003"/>
66+
</testsuite>
Binary file not shown.

0 commit comments

Comments
 (0)