Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_3
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_mszczonow_3
Commits
358fa3bf
Commit
358fa3bf
authored
Jul 25, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@Autowired
parent
e26c03e2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
KalkulatorController.java
src/main/java/alx/kalkulator/KalkulatorController.java
+4
-7
LogikaKalkulatora.java
src/main/java/alx/kalkulator/LogikaKalkulatora.java
+19
-0
No files found.
src/main/java/alx/kalkulator/KalkulatorController.java
View file @
358fa3bf
package
alx
.
kalkulator
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -9,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping
(
"/kalkulator"
)
public
class
KalkulatorController
{
@Autowired
private
LogikaKalkulatora
logika
;
@GetMapping
public
String
kalkulatorGet
()
{
...
...
@@ -17,13 +20,7 @@ public class KalkulatorController {
@PostMapping
public
String
kalkulator
(
Long
liczba1
,
Long
liczba2
,
String
operacja
,
Model
model
)
{
Long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0L
;
};
Long
wynik
=
logika
.
oblicz
(
liczba1
,
liczba2
,
operacja
);
model
.
addAttribute
(
"wynik"
,
wynik
);
return
"kalkulator.html"
;
}
...
...
src/main/java/alx/kalkulator/LogikaKalkulatora.java
0 → 100644
View file @
358fa3bf
package
alx
.
kalkulator
;
import
org.springframework.stereotype.Component
;
@Component
public
class
LogikaKalkulatora
{
public
long
oblicz
(
long
liczba1
,
long
liczba2
,
String
operacja
)
{
long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
default
->
0L
;
};
return
wynik
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment