-
Notifications
You must be signed in to change notification settings - Fork 22
Develop triangle #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Develop triangle #120
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,58 @@ | ||
| TODO replace me | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-parent</artifactId> | ||
| <version>3.4.3</version> | ||
| <relativePath/> <!-- lookup parent from repository --> | ||
| </parent> | ||
| <groupId>com.example</groupId> | ||
| <artifactId>triangle-ssr</artifactId> | ||
| <version>0.0.1-SNAPSHOT</version> | ||
| <name>TriangleSSR</name> | ||
| <description>TriangleSSR</description> | ||
| <url/> | ||
| <licenses> | ||
| <license/> | ||
| </licenses> | ||
| <developers> | ||
| <developer/> | ||
| </developers> | ||
| <scm> | ||
| <connection/> | ||
| <developerConnection/> | ||
| <tag/> | ||
| <url/> | ||
| </scm> | ||
| <properties> | ||
| <java.version>21</java.version> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-web</artifactId> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> |
62 changes: 62 additions & 0 deletions
62
...1_maven/cs/web/triangle-ssr/src/main/java/com/example/springmvcdocker/FormController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.example.springmvcdocker; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
|
|
||
| @Controller | ||
| public class FormController { | ||
|
|
||
| @GetMapping("/") | ||
| public String showForm() { | ||
| return "index"; | ||
| } | ||
|
|
||
| @PostMapping("/process") | ||
| public String processForm( | ||
| @RequestParam("a") int a, | ||
| @RequestParam("b") int b, | ||
| @RequestParam("c") int c) | ||
| { | ||
| int value = TriangleClassification.classify(a, b, c); | ||
| String triangleType = getTriangleType(value); | ||
| return "redirect:/" + triangleType.toLowerCase().replace(" ", "-"); | ||
| } | ||
|
|
||
| @RequestMapping("/not-a-triangle") | ||
| public String notATriangle(Model model) { | ||
| model.addAttribute("output", "The input does not form a triangle."); | ||
| return "notTriangle"; | ||
| } | ||
|
|
||
| @RequestMapping("/scalene-triangle") | ||
| public String scaleneTriangle(Model model) { | ||
| model.addAttribute("output", "This is a Scalene triangle."); | ||
| return "scalene"; | ||
| } | ||
|
|
||
| @RequestMapping("/isosceles-triangle") | ||
| public String isoscelesTriangle(Model model) { | ||
| model.addAttribute("output", "This is an Isosceles triangle."); | ||
| return "isosceles"; | ||
| } | ||
|
|
||
| @RequestMapping("/equilateral-triangle") | ||
| public String equilateralTriangle(Model model) { | ||
| model.addAttribute("output", "This is an Equilateral triangle."); | ||
| return "equilateral"; | ||
| } | ||
|
|
||
| public static String getTriangleType(int value) { | ||
| switch (value) { | ||
| case 0: return "Not a triangle"; | ||
| case 1: return "Scalene triangle"; | ||
| case 2: return "Isosceles triangle"; | ||
| case 3: return "Equilateral triangle"; | ||
| default: return "Invalid input"; | ||
| } | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
...cs/web/triangle-ssr/src/main/java/com/example/springmvcdocker/TriangleClassification.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.example.springmvcdocker; | ||
|
|
||
| public class TriangleClassification { | ||
|
|
||
| public static int classify(int a, int b, int c) { | ||
|
|
||
| if (a <= 0 || b <= 0 || c <= 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| if (a == b && b == c) { | ||
| return 3; | ||
| } | ||
|
|
||
| int max = Math.max(a, Math.max(b, c)); | ||
|
|
||
| if ((max == a && max - b - c >= 0) || | ||
| (max == b && max - a - c >= 0) || | ||
| (max == c && max - a - b >= 0)) { | ||
| return 0; | ||
| } | ||
|
|
||
| if (a == b || b == c || a == c) { | ||
| return 2; | ||
| } else { | ||
| return 1; | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...cs/web/triangle-ssr/src/main/java/com/example/springmvcdocker/TriangleSSRApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.example.springmvcdocker; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class TriangleSSRApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(TriangleSSRApplication.class, args); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
jdk_21_maven/cs/web/triangle-ssr/src/main/resources/templates/equilateral.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <title>Equilateral Triangle</title> | ||
| </head> | ||
| <body> | ||
| <h2><span th:text="${output}"></span></h2> | ||
| <a href="/"> << Go back</a> | ||
| </body> | ||
| </html> |
23 changes: 23 additions & 0 deletions
23
jdk_21_maven/cs/web/triangle-ssr/src/main/resources/templates/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <title>SUT</title> | ||
| </head> | ||
| <body> | ||
| <h1>Spring MVC test app</h1> | ||
| <h2>Triangle classification</h2> | ||
| <h2>Enter side values:</h2> | ||
| <form action="/process" method="post"> | ||
| <label for="a">Side A:</label> | ||
| <input type="number" id="a" name="a" required><br><br> | ||
|
|
||
| <label for="b">Side B:</label> | ||
| <input type="number" id="b" name="b" required><br><br> | ||
|
|
||
| <label for="c">Side C:</label> | ||
| <input type="number" id="c" name="c" required><br><br> | ||
|
|
||
| <button type="submit">Submit</button> | ||
| </form> | ||
| </body> | ||
| </html> |
10 changes: 10 additions & 0 deletions
10
jdk_21_maven/cs/web/triangle-ssr/src/main/resources/templates/isosceles.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <title>Isosceles Triangle</title> | ||
| </head> | ||
| <body> | ||
| <h2><span th:text="${output}"></span></h2> | ||
| <a href="/"> << Go back</a> | ||
| </body> | ||
| </html> |
10 changes: 10 additions & 0 deletions
10
jdk_21_maven/cs/web/triangle-ssr/src/main/resources/templates/notTriangle.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <title>Not a Triangle</title> | ||
| </head> | ||
| <body> | ||
| <h2><span th:text="${output}"></span></h2> | ||
| <a href="/"> << Go back</a> | ||
| </body> | ||
| </html> |
10 changes: 10 additions & 0 deletions
10
jdk_21_maven/cs/web/triangle-ssr/src/main/resources/templates/scalene.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns:th="http://www.thymeleaf.org"> | ||
| <head> | ||
| <title>Scalene Triangle</title> | ||
| </head> | ||
| <body> | ||
| <h2><span th:text="${output}"></span></h2> | ||
| <a href="/"> << Go back</a> | ||
| </body> | ||
| </html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this endpoint? wouldn't make more sense that root "/" is mapped into "index.html"? ie
@GetMapping("/") ... return "index.html"?