Skip to content

Commit 3378187

Browse files
committed
Add 'Simple Math' GUI version solution
1 parent d613701 commit 3378187

File tree

12 files changed

+293
-7
lines changed

12 files changed

+293
-7
lines changed

gradle/libs.versions.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
21
[versions]
32
assertj-core = "3.26.3"
4-
junit-jupiter = "5.11.0"
53
javafxplugin = "0.1.0"
4+
junit-jupiter = "5.11.0"
65
pmd = "7.6.0"
6+
spring-boot = "3.3.5"
77

88
[libraries]
99
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj-core" }
10+
htmlunit = { module = "net.sourceforge.htmlunit:htmlunit" }
1011
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
12+
spring-boot-dependencies = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "spring-boot" }
13+
spring-boot-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "spring-boot" }
14+
spring-boot-starter-web = { module = "org.springframework.boot:spring-boot-starter-web", version.ref = "spring-boot" }
1115

1216
[plugins]
1317
javafxplugin = { id = "org.openjfx.javafxplugin", version.ref = "javafxplugin" }
18+
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }

simple-math/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
plugins {
22
id 'com.craftsmanshipinsoftware.common-conventions'
3+
alias(libs.plugins.spring.boot)
34
}
45

56
dependencies {
7+
implementation enforcedPlatform(libs.spring.boot.dependencies)
8+
implementation(libs.spring.boot.starter.web)
9+
10+
testImplementation(libs.spring.boot.starter.test)
611
testImplementation(libs.assertj.core)
712
testImplementation(libs.junit.jupiter)
13+
testImplementation(libs.htmlunit)
814
}

simple-math/src/main/java/com/craftsmanshipinsoftware/math/Main.java renamed to simple-math/src/main/java/com/craftsmanshipinsoftware/math/console/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.craftsmanshipinsoftware.math;
1+
package com.craftsmanshipinsoftware.math.console;
22

33
public class Main {
44

simple-math/src/main/java/com/craftsmanshipinsoftware/math/PositiveInteger.java renamed to simple-math/src/main/java/com/craftsmanshipinsoftware/math/console/PositiveInteger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.craftsmanshipinsoftware.math;
1+
package com.craftsmanshipinsoftware.math.console;
22

33
import java.io.Serial;
44

simple-math/src/main/java/com/craftsmanshipinsoftware/math/SimpleMath.java renamed to simple-math/src/main/java/com/craftsmanshipinsoftware/math/console/SimpleMath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.craftsmanshipinsoftware.math;
1+
package com.craftsmanshipinsoftware.math.console;
22

33
import java.io.InputStream;
44
import java.io.PrintStream;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.craftsmanshipinsoftware.math.gui;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Simple Math</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Simple Math</h1>
12+
<label for="firstInput">What is the first number?</label>
13+
<input type="number" id="firstInput" placeholder="Enter the first number" value="10"/>
14+
<br>
15+
<label for="secondInput">What is the second number?</label>
16+
<input type="number" id="secondInput" placeholder="Enter the second number" value="5"/>
17+
<div class="calculation" id="addition"></div>
18+
<div class="calculation" id="subtraction"></div>
19+
<div class="calculation" id="multiplication"></div>
20+
<div class="calculation" id="division"></div>
21+
<button id="resetButton">Reset to default</button>
22+
</div>
23+
<script src="script.js"></script>
24+
</body>
25+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const firstInput = document.getElementById('firstInput');
2+
const secondInput = document.getElementById('secondInput');
3+
const addition = document.getElementById('addition');
4+
const subtraction = document.getElementById('subtraction');
5+
const multiplication = document.getElementById('multiplication');
6+
const division = document.getElementById('division');
7+
const resetButton = document.getElementById('resetButton');
8+
9+
function formatNumber(num) {
10+
return num % 1 === 0 ? num : parseFloat(num.toFixed(2));
11+
}
12+
13+
function updateCalculations() {
14+
const firstNumber = parseFloat(firstInput.value) || 0;
15+
const secondNumber = parseFloat(secondInput.value) || 0;
16+
addition.textContent = `${firstNumber} + ${secondNumber} = ${firstNumber + secondNumber}`;
17+
subtraction.textContent = `${firstNumber} - ${secondNumber} = ${firstNumber - secondNumber}`;
18+
multiplication.textContent = `${firstNumber} × ${secondNumber} = ${firstNumber * secondNumber}`;
19+
const quotient = formatNumber(firstNumber / secondNumber);
20+
division.textContent = secondNumber !== 0 ? `${firstNumber} ÷ ${secondNumber} = ${quotient}`
21+
: 'Cannot divide by zero!';
22+
}
23+
24+
firstInput.addEventListener('input', updateCalculations);
25+
secondInput.addEventListener('input', updateCalculations);
26+
resetButton.addEventListener('click', () => {
27+
firstInput.value = 10;
28+
secondInput.value = 5;
29+
updateCalculations();
30+
});
31+
32+
updateCalculations();
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
body {
2+
font-family: Helvetica, sans-serif;
3+
margin: 0;
4+
background-color: #f0f4f8;
5+
height: 100vh;
6+
display: flex;
7+
justify-content: center;
8+
align-items: center;
9+
}
10+
11+
.container {
12+
background-color: #fff;
13+
padding: 20px 30px;
14+
border-radius: 10px;
15+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
16+
width: 100%;
17+
max-width: 400px;
18+
}
19+
20+
h1 {
21+
color: #333;
22+
font-size: 24px;
23+
margin-bottom: 20px;
24+
}
25+
26+
label {
27+
font-size: 16px;
28+
display: block;
29+
margin-bottom: 8px;
30+
color: #444;
31+
text-align: left;
32+
}
33+
34+
input[type="number"], .calculation {
35+
box-sizing: border-box;
36+
width: 100%;
37+
padding: 10px;
38+
font-size: 16px;
39+
border: 1px solid #ccc;
40+
border-radius: 5px;
41+
margin-bottom: 20px;
42+
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
43+
font-family: "Courier New", Courier, monospace;
44+
}
45+
46+
input[type="number"]:focus {
47+
border-color: #007BFF;
48+
outline: none;
49+
box-shadow: 0 0 4px rgba(0, 123, 255, 0.3);
50+
}
51+
52+
.calculation {
53+
font-size: 18px;
54+
background-color: #f9f9f9;
55+
border: 1px solid #ddd;
56+
}
57+
58+
#resetButton {
59+
margin-top: 10px;
60+
padding: 10px 20px;
61+
font-size: 16px;
62+
border: none;
63+
border-radius: 5px;
64+
background-color: #FF6347;
65+
color: white;
66+
cursor: pointer;
67+
display: block;
68+
margin-left: auto;
69+
margin-right: auto;
70+
text-align: center;
71+
}
72+
73+
#resetButton:hover {
74+
background-color: #ff4b3a;
75+
}

simple-math/src/test/java/com/craftsmanshipinsoftware/math/PositiveIntegerTest.java renamed to simple-math/src/test/java/com/craftsmanshipinsoftware/math/console/PositiveIntegerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.craftsmanshipinsoftware.math;
1+
package com.craftsmanshipinsoftware.math.console;
22

33
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
44

0 commit comments

Comments
 (0)