Skip to content

Commit 44a0df2

Browse files
committed
feat: add boilerplate and tests
1 parent c741ed7 commit 44a0df2

File tree

14 files changed

+743
-27
lines changed

14 files changed

+743
-27
lines changed

README.md

Lines changed: 315 additions & 27 deletions
Large diffs are not rendered by default.

pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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+
6+
<groupId>com.cbfacademy</groupId>
7+
<artifactId>spring-boot</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>pom</packaging>
10+
11+
<name>spring-boot</name>
12+
<url>https://codingblackfemales.com/academy</url>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
18+
<java.version>21</java.version>
19+
<junit.jupiter.version>5.9.0</junit.jupiter.version>
20+
<junit.platform.version>1.9.0</junit.platform.version>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.junit.jupiter</groupId>
26+
<artifactId>junit-jupiter-api</artifactId>
27+
<version>${junit.jupiter.version}</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter-engine</artifactId>
33+
<version>${junit.jupiter.version}</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.junit.jupiter</groupId>
38+
<artifactId>junit-jupiter-params</artifactId>
39+
<version>${junit.jupiter.version}</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.hamcrest</groupId>
44+
<artifactId>hamcrest-all</artifactId>
45+
<version>1.3</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<pluginManagement>
52+
<plugins>
53+
<plugin>
54+
<artifactId>maven-surefire-plugin</artifactId>
55+
<version>3.0.0</version>
56+
<dependencies>
57+
<dependency>
58+
<groupId>org.junit.jupiter</groupId>
59+
<artifactId>junit-jupiter-engine</artifactId>
60+
<version>${junit.jupiter.version}</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>me.fabriciorby</groupId>
64+
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
65+
<version>1.1.0</version>
66+
</dependency>
67+
</dependencies>
68+
<configuration>
69+
<includes>
70+
<include>**/*.java</include>
71+
</includes>
72+
<reportFormat>plain</reportFormat>
73+
<consoleOutputReporter>
74+
<disable>true</disable>
75+
</consoleOutputReporter>
76+
<statelessTestsetInfoReporter
77+
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporterUnicode"/>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</pluginManagement>
82+
</build>
83+
84+
<modules>
85+
<module>software-design</module>
86+
<module>rest-api</module>
87+
</modules>
88+
</project>

rest-api/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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+
<parent>
6+
<artifactId>spring-boot</artifactId>
7+
<groupId>com.cbfacademy</groupId>
8+
<version>1.0.0</version>
9+
</parent>
10+
11+
<groupId>com.cbfacademy</groupId>
12+
<artifactId>rest-api</artifactId>
13+
<version>1.0.0</version>
14+
15+
<name>rest-api</name>
16+
17+
<build>
18+
<pluginManagement>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-compiler-plugin</artifactId>
23+
<configuration>
24+
<testExcludes>
25+
<!-- <testExclude>**/ShowroomTest.java</testExclude> -->
26+
</testExcludes>
27+
</configuration>
28+
</plugin>
29+
</plugins>
30+
</pluginManagement>
31+
</build>
32+
</project>

software-design/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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+
<parent>
6+
<artifactId>spring-boot</artifactId>
7+
<groupId>com.cbfacademy</groupId>
8+
<version>1.0.0</version>
9+
</parent>
10+
11+
<groupId>com.cbfacademy</groupId>
12+
<artifactId>software-design</artifactId>
13+
<version>1.0.0</version>
14+
15+
<name>software-design</name>
16+
17+
<build>
18+
<plugins>
19+
<plugin>
20+
<groupId>org.codehaus.mojo</groupId>
21+
<artifactId>exec-maven-plugin</artifactId>
22+
<version>3.5.1</version>
23+
<configuration>
24+
<mainClass>com.cbfacademy.App</mainClass>
25+
</configuration>
26+
</plugin>
27+
</plugins>
28+
<pluginManagement>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-compiler-plugin</artifactId>
33+
<configuration>
34+
<testExcludes>
35+
<!-- <testExclude>**/ShowroomTest.java</testExclude> -->
36+
</testExcludes>
37+
</configuration>
38+
</plugin>
39+
</plugins>
40+
</pluginManagement>
41+
</build>
42+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.cbfacademy;
2+
3+
public class App {
4+
public static void main(String[] args) {
5+
DiceGame game = new DiceGame();
6+
String winner = game.play();
7+
8+
if (winner == null) {
9+
System.out.println("It's a draw!");
10+
} else {
11+
System.out.println(winner + " wins!");
12+
}
13+
}
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.cbfacademy;
2+
3+
public class DiceGame {
4+
private DicePlayer player1;
5+
private DicePlayer player2;
6+
private int targetScore = 30;
7+
8+
public DiceGame() {
9+
player1 = new DicePlayer();
10+
player2 = new DicePlayer();
11+
player1.setName("Player 1");
12+
player2.setName("Player 2");
13+
}
14+
15+
public String play() {
16+
int score1 = 0;
17+
int score2 = 0;
18+
String winner = null;
19+
20+
System.out.println("Game started. Target score: " + targetScore);
21+
System.out.println();
22+
23+
while (score1 < targetScore && score2 < targetScore) {
24+
score1 += player1.roll();
25+
score2 += player2.roll();
26+
System.out.println();
27+
}
28+
29+
if(score1 > score2) {
30+
winner = player1.getName();
31+
} else if (score2 > score1) {
32+
player2.getName();
33+
}
34+
35+
return winner;
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.cbfacademy;
2+
3+
public class DicePlayer {
4+
private String name;
5+
6+
public String getName() {
7+
return name;
8+
}
9+
10+
public void setName(String name) {
11+
this.name = name;
12+
}
13+
14+
public int roll() {
15+
int score = (int) (Math.random() * 6) + 1;
16+
17+
System.out.println(name + " rolled a " + score);
18+
19+
return score;
20+
}
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.cbfacademy;
2+
3+
/**
4+
* Represents an object that can be played.
5+
*/
6+
public interface Game {
7+
/**
8+
* Plays the game.
9+
* @return A string representing the winner of the game.
10+
*/
11+
String play();
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.cbfacademy;
2+
3+
public class GameFactory {
4+
/**
5+
* Creates a new dice game.
6+
*
7+
* @return A dice game.
8+
*/
9+
public static DiceGame create() {
10+
return new DiceGame();
11+
}
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.cbfacademy;
2+
3+
/**
4+
* Represents a player that can roll a die.
5+
*/
6+
public interface Player extends Rollable {
7+
/**
8+
* Gets the name of the player.
9+
*
10+
* @return The name of the player.
11+
*/
12+
String getName();
13+
14+
/**
15+
* Sets the name of the player.
16+
*
17+
* @param name The name of the player.
18+
*/
19+
void setName(String name);
20+
}

0 commit comments

Comments
 (0)