diff --git a/Guess The Number Game/pom.xml b/Guess The Number Game/pom.xml new file mode 100644 index 00000000..ed0c8427 --- /dev/null +++ b/Guess The Number Game/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + br.com.exemplo + meu-projeto + 1.0-SNAPSHOT + + + 1.8 + 1.8 + + + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + diff --git a/Guess The Number Game/src/main/java/learningspace/swtest/examples/GameLogic.java b/Guess The Number Game/src/main/java/learningspace/swtest/examples/GameLogic.java new file mode 100644 index 00000000..d8007850 --- /dev/null +++ b/Guess The Number Game/src/main/java/learningspace/swtest/examples/GameLogic.java @@ -0,0 +1,13 @@ +package learningspace.swtest.examples; + +public class GameLogic { + public String checkGuess(int guess, int correctNumber) { + if (guess == correctNumber) { + return "Correct!"; + } else if (guess < correctNumber) { + return "Too low!"; + } else { + return "Too high!"; + } + } +} diff --git a/Guess The Number Game/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java b/Guess The Number Game/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java new file mode 100644 index 00000000..3a3951dc --- /dev/null +++ b/Guess The Number Game/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java @@ -0,0 +1,48 @@ +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class GuessTheNumberGame extends Application { + private int targetNumber = (int) (Math.random() * 100) + 1; + private int numberOfTries = 0; + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage primaryStage) { + primaryStage.setTitle("Guess the Number Game"); + + Label titleLabel = new Label("Guess the Number (1-100)"); + TextField guessInput = new TextField(); + guessInput.setId("guessInput"); // ID adicionado + Label messageLabel = new Label(); + messageLabel.setId("messageLabel"); // ID adicionado + VBox vbox = new VBox(titleLabel, guessInput, messageLabel); + + guessInput.setOnAction(e -> { + try { + int userGuess = Integer.parseInt(guessInput.getText()); + numberOfTries++; + if (userGuess < targetNumber) { + messageLabel.setText("Try higher."); + } else if (userGuess > targetNumber) { + messageLabel.setText("Try lower."); + } else { + messageLabel.setText("Congratulations! You guessed the number in " + numberOfTries + " tries."); + } + guessInput.clear(); + } catch (NumberFormatException ex) { + messageLabel.setText("Invalid input. Enter a number."); + } + }); + + Scene scene = new Scene(vbox, 300, 150); + primaryStage.setScene(scene); + primaryStage.show(); + } +} diff --git a/Guess The Number Game/src/test/java/learningspace/swtest/examples/GameLogicTest.java b/Guess The Number Game/src/test/java/learningspace/swtest/examples/GameLogicTest.java new file mode 100644 index 00000000..0f8aae18 --- /dev/null +++ b/Guess The Number Game/src/test/java/learningspace/swtest/examples/GameLogicTest.java @@ -0,0 +1,24 @@ +import learningspace.swtest.examples.GameLogic; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class GameLogicTest { + + @Test + void testCorrectGuess() { + GameLogic logic = new GameLogic(); + assertEquals("Correct!", logic.checkGuess(7, 7)); + } + + @Test + void testTooLow() { + GameLogic logic = new GameLogic(); + assertEquals("Too low!", logic.checkGuess(5, 7)); + } + + @Test + void testTooHigh() { + GameLogic logic = new GameLogic(); + assertEquals("Too high!", logic.checkGuess(9, 7)); + } +} diff --git a/Guess The Number Game/target/classes/GuessTheNumberGame.class b/Guess The Number Game/target/classes/GuessTheNumberGame.class new file mode 100644 index 00000000..9c82d22d Binary files /dev/null and b/Guess The Number Game/target/classes/GuessTheNumberGame.class differ diff --git a/Guess The Number Game/target/classes/learningspace/swtest/examples/GameLogic.class b/Guess The Number Game/target/classes/learningspace/swtest/examples/GameLogic.class new file mode 100644 index 00000000..7fd77e7c Binary files /dev/null and b/Guess The Number Game/target/classes/learningspace/swtest/examples/GameLogic.class differ diff --git a/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..303939f5 --- /dev/null +++ b/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +GuessTheNumberGame.class +learningspace\swtest\examples\GameLogic.class diff --git a/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..3ec9ef3e --- /dev/null +++ b/Guess The Number Game/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GameLogic.java +C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GuessTheNumberGame.java diff --git a/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..3c94ca94 --- /dev/null +++ b/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +GameLogicTest.class diff --git a/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..545e780c --- /dev/null +++ b/Guess The Number Game/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\anell\Downloads\trabalho\Guess the number\src\test\java\learningspace\swtest\examples\GameLogicTest.java diff --git a/Guess The Number Game/target/surefire-reports/GameLogicTest.txt b/Guess The Number Game/target/surefire-reports/GameLogicTest.txt new file mode 100644 index 00000000..c77390b5 --- /dev/null +++ b/Guess The Number Game/target/surefire-reports/GameLogicTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: GameLogicTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.082 s -- in GameLogicTest diff --git a/Guess The Number Game/target/surefire-reports/TEST-GameLogicTest.xml b/Guess The Number Game/target/surefire-reports/TEST-GameLogicTest.xml new file mode 100644 index 00000000..860f7505 --- /dev/null +++ b/Guess The Number Game/target/surefire-reports/TEST-GameLogicTest.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Guess The Number Game/target/test-classes/GameLogicTest.class b/Guess The Number Game/target/test-classes/GameLogicTest.class new file mode 100644 index 00000000..d7d10369 Binary files /dev/null and b/Guess The Number Game/target/test-classes/GameLogicTest.class differ diff --git a/Guess the number/pom.xml b/Guess the number/pom.xml new file mode 100644 index 00000000..ed0c8427 --- /dev/null +++ b/Guess the number/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + br.com.exemplo + meu-projeto + 1.0-SNAPSHOT + + + 1.8 + 1.8 + + + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + + diff --git a/Guess the number/src/main/java/learningspace/swtest/examples/GameLogic.java b/Guess the number/src/main/java/learningspace/swtest/examples/GameLogic.java new file mode 100644 index 00000000..d8007850 --- /dev/null +++ b/Guess the number/src/main/java/learningspace/swtest/examples/GameLogic.java @@ -0,0 +1,13 @@ +package learningspace.swtest.examples; + +public class GameLogic { + public String checkGuess(int guess, int correctNumber) { + if (guess == correctNumber) { + return "Correct!"; + } else if (guess < correctNumber) { + return "Too low!"; + } else { + return "Too high!"; + } + } +} diff --git a/Guess the number/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java b/Guess the number/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java new file mode 100644 index 00000000..3a3951dc --- /dev/null +++ b/Guess the number/src/main/java/learningspace/swtest/examples/GuessTheNumberGame.java @@ -0,0 +1,48 @@ +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; + +public class GuessTheNumberGame extends Application { + private int targetNumber = (int) (Math.random() * 100) + 1; + private int numberOfTries = 0; + + public static void main(String[] args) { + launch(args); + } + + @Override + public void start(Stage primaryStage) { + primaryStage.setTitle("Guess the Number Game"); + + Label titleLabel = new Label("Guess the Number (1-100)"); + TextField guessInput = new TextField(); + guessInput.setId("guessInput"); // ID adicionado + Label messageLabel = new Label(); + messageLabel.setId("messageLabel"); // ID adicionado + VBox vbox = new VBox(titleLabel, guessInput, messageLabel); + + guessInput.setOnAction(e -> { + try { + int userGuess = Integer.parseInt(guessInput.getText()); + numberOfTries++; + if (userGuess < targetNumber) { + messageLabel.setText("Try higher."); + } else if (userGuess > targetNumber) { + messageLabel.setText("Try lower."); + } else { + messageLabel.setText("Congratulations! You guessed the number in " + numberOfTries + " tries."); + } + guessInput.clear(); + } catch (NumberFormatException ex) { + messageLabel.setText("Invalid input. Enter a number."); + } + }); + + Scene scene = new Scene(vbox, 300, 150); + primaryStage.setScene(scene); + primaryStage.show(); + } +} diff --git a/Guess the number/src/test/java/learningspace/swtest/examples/GameLogicTest.java b/Guess the number/src/test/java/learningspace/swtest/examples/GameLogicTest.java new file mode 100644 index 00000000..0f8aae18 --- /dev/null +++ b/Guess the number/src/test/java/learningspace/swtest/examples/GameLogicTest.java @@ -0,0 +1,24 @@ +import learningspace.swtest.examples.GameLogic; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class GameLogicTest { + + @Test + void testCorrectGuess() { + GameLogic logic = new GameLogic(); + assertEquals("Correct!", logic.checkGuess(7, 7)); + } + + @Test + void testTooLow() { + GameLogic logic = new GameLogic(); + assertEquals("Too low!", logic.checkGuess(5, 7)); + } + + @Test + void testTooHigh() { + GameLogic logic = new GameLogic(); + assertEquals("Too high!", logic.checkGuess(9, 7)); + } +} diff --git a/Guess the number/target/classes/GuessTheNumberGame.class b/Guess the number/target/classes/GuessTheNumberGame.class new file mode 100644 index 00000000..9c82d22d Binary files /dev/null and b/Guess the number/target/classes/GuessTheNumberGame.class differ diff --git a/Guess the number/target/classes/learningspace/swtest/examples/GameLogic.class b/Guess the number/target/classes/learningspace/swtest/examples/GameLogic.class new file mode 100644 index 00000000..7fd77e7c Binary files /dev/null and b/Guess the number/target/classes/learningspace/swtest/examples/GameLogic.class differ diff --git a/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 00000000..303939f5 --- /dev/null +++ b/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +GuessTheNumberGame.class +learningspace\swtest\examples\GameLogic.class diff --git a/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 00000000..3ec9ef3e --- /dev/null +++ b/Guess the number/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GameLogic.java +C:\Users\anell\Downloads\trabalho\Guess the number\src\main\java\learningspace\swtest\examples\GuessTheNumberGame.java diff --git a/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst new file mode 100644 index 00000000..3c94ca94 --- /dev/null +++ b/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -0,0 +1 @@ +GameLogicTest.class diff --git a/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 00000000..545e780c --- /dev/null +++ b/Guess the number/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\anell\Downloads\trabalho\Guess the number\src\test\java\learningspace\swtest\examples\GameLogicTest.java diff --git a/Guess the number/target/surefire-reports/GameLogicTest.txt b/Guess the number/target/surefire-reports/GameLogicTest.txt new file mode 100644 index 00000000..c77390b5 --- /dev/null +++ b/Guess the number/target/surefire-reports/GameLogicTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: GameLogicTest +------------------------------------------------------------------------------- +Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.082 s -- in GameLogicTest diff --git a/Guess the number/target/surefire-reports/TEST-GameLogicTest.xml b/Guess the number/target/surefire-reports/TEST-GameLogicTest.xml new file mode 100644 index 00000000..860f7505 --- /dev/null +++ b/Guess the number/target/surefire-reports/TEST-GameLogicTest.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Guess the number/target/test-classes/GameLogicTest.class b/Guess the number/target/test-classes/GameLogicTest.class new file mode 100644 index 00000000..d7d10369 Binary files /dev/null and b/Guess the number/target/test-classes/GameLogicTest.class differ