Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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
java_dzienna_15_09
Commits
a89247ed
Commit
a89247ed
authored
Oct 04, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LogikaKalkulatora z metodą statyczną
parent
b3b3b03c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
Kalkulator.java
PC29-Spring/src/main/java/com/example/demo/Kalkulator.java
+3
-8
LogikaKalkulatora.java
...ing/src/main/java/com/example/demo/LogikaKalkulatora.java
+15
-0
No files found.
PC29-Spring/src/main/java/com/example/demo/Kalkulator.java
View file @
a89247ed
...
@@ -19,15 +19,10 @@ public class Kalkulator {
...
@@ -19,15 +19,10 @@ public class Kalkulator {
// do tej metody - wystarczy zadeklarować parametry o tej samej nazwie.
// do tej metody - wystarczy zadeklarować parametry o tej samej nazwie.
@PostMapping
@PostMapping
public
String
kalkulatorPost
(
Model
model
,
Long
liczba1
,
Long
liczba2
,
String
operacja
)
{
public
String
kalkulatorPost
(
Model
model
,
Long
liczba1
,
Long
liczba2
,
String
operacja
)
{
long
wynik
=
switch
(
operacja
)
{
long
wynik
=
LogikaKalkulatora
.
oblicz
(
operacja
,
liczba1
,
liczba2
);
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
case
"%"
->
liczba1
%
liczba2
;
default
->
0
;
};
model
.
addAttribute
(
"wynik"
,
wynik
);
model
.
addAttribute
(
"wynik"
,
wynik
);
return
"kalkulator.html"
;
return
"kalkulator.html"
;
}
}
}
}
PC29-Spring/src/main/java/com/example/demo/LogikaKalkulatora.java
0 → 100644
View file @
a89247ed
package
com
.
example
.
demo
;
public
class
LogikaKalkulatora
{
public
static
long
oblicz
(
String
operacja
,
long
liczba1
,
long
liczba2
)
{
long
wynik
=
switch
(
operacja
)
{
case
"+"
->
liczba1
+
liczba2
;
case
"-"
->
liczba1
-
liczba2
;
case
"*"
->
liczba1
*
liczba2
;
case
"/"
->
liczba1
/
liczba2
;
case
"%"
->
liczba1
%
liczba2
;
default
->
0
;
};
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