Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_java_alx_20240321
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
kurs_java_alx_20240321
Commits
49ecfac2
Commit
49ecfac2
authored
Apr 10, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
importowanie - przed poprawkami
parent
75501319
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
+98
-0
Program2.java
src/p10_importowanie/Program2.java
+98
-0
No files found.
src/p10_importowanie/Program2.java
0 → 100644
View file @
49ecfac2
package
p10_importowanie
;
import
java.util.Scanner
;
public
class
Program2
{
public
static
void
main
(
String
[]
args
)
{
@SuppressWarnings
(
"resource"
)
Scanner
scanner
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
" K - kwadrat"
);
System
.
out
.
println
(
" O - koło"
);
System
.
out
.
println
(
" P - prostokąt"
);
System
.
out
.
println
(
" T - trójkąt"
);
System
.
out
.
println
(
" KM - przelicz kilometry na mile"
);
System
.
out
.
println
(
" MK - przelicz mile na kilometry"
);
System
.
out
.
println
(
" CF - przelicz °C na °F"
);
System
.
out
.
println
(
" FC - przelicz °F na °C"
);
System
.
out
.
println
(
" Q - zakończ"
);
petla:
while
(
true
)
{
System
.
out
.
println
(
"\nWybierz figurę lub operację:"
);
String
wybor
=
scanner
.
next
().
toUpperCase
();
switch
(
wybor
)
{
case
"Q"
->
{
break
petla
;
}
case
"K"
->
{
System
.
out
.
print
(
"Podaj długość boku kwadratu: "
);
double
a
=
scanner
.
nextDouble
();
double
pole
=
Geometria
.
poleKwadratu
(
a
);
double
obwod
=
Geometria
.
obwodKwadratu
(
a
);
System
.
out
.
printf
(
"Dla kwadratu o boku %.3f pole wynosi %.3f, a obwód %.3f\n"
,
a
,
pole
,
obwod
);
}
case
"P"
->
{
System
.
out
.
print
(
"Podaj dwie długości boków prostokąta: "
);
double
a
=
scanner
.
nextDouble
();
double
b
=
scanner
.
nextDouble
();
double
pole
=
Geometria
.
poleProstokata
(
a
,
b
);
double
obwod
=
Geometria
.
obwodProstokata
(
a
,
b
);
System
.
out
.
printf
(
"Dla prostokąta o bokach %.3f i %.3f pole wynosi %.3f, a obwód %.3f\n"
,
a
,
b
,
pole
,
obwod
);
}
case
"O"
->
{
System
.
out
.
print
(
"Podaj promień koła: "
);
double
r
=
scanner
.
nextDouble
();
double
pole
=
Geometria
.
poleKola
(
r
);
double
obwod
=
Geometria
.
obwodKola
(
r
);
System
.
out
.
printf
(
"Dla koła o promieniu %.3f pole wynosi %.3f, a obwód %.3f\n"
,
r
,
pole
,
obwod
);
}
case
"T"
->
{
System
.
out
.
print
(
"Podaj trzy długości boków trójkąta: "
);
double
a
=
scanner
.
nextDouble
();
double
b
=
scanner
.
nextDouble
();
double
c
=
scanner
.
nextDouble
();
if
(
Geometria
.
warunekTrojkata
(
a
,
b
,
c
))
{
double
pole
=
Geometria
.
poleTrojkata
(
a
,
b
,
c
);
double
obwod
=
Geometria
.
obwodTrojkata
(
a
,
b
,
c
);
System
.
out
.
printf
(
"Dla prostokąta o bokach %.3f %.3f %.3f pole wynosi %.3f, a obwód %.3f\n"
,
a
,
b
,
c
,
pole
,
obwod
);
}
else
{
System
.
out
.
println
(
"Z tych liczb nie da się złożyć trójkąta"
);
}
}
case
"KM"
->
{
System
.
out
.
print
(
"Podaj odległość w kilometrach: "
);
double
km
=
scanner
.
nextDouble
();
double
wynik
=
JednostkiMiary
.
km_na_mile
(
km
);
System
.
out
.
printf
(
"%.3f km = %.3f mil\n"
,
km
,
wynik
);
}
case
"MK"
->
{
System
.
out
.
print
(
"Podaj odległość w milach: "
);
double
mile
=
scanner
.
nextDouble
();
double
wynik
=
JednostkiMiary
.
mile_na_km
(
mile
);
System
.
out
.
printf
(
"%.3f mil = %.3f km\n"
,
mile
,
wynik
);
}
case
"FC"
->
{
System
.
out
.
print
(
"Podaj temperaturę w Fahrenheitach: "
);
double
f
=
scanner
.
nextDouble
();
double
wynik
=
JednostkiMiary
.
f_na_c
(
f
);
System
.
out
.
printf
(
"%.3f °F = %.3f °C\n"
,
f
,
wynik
);
}
case
"CF"
->
{
System
.
out
.
print
(
"Podaj temperaturę w Celsjuszach: "
);
double
c
=
scanner
.
nextDouble
();
double
wynik
=
JednostkiMiary
.
c_na_f
(
c
);
System
.
out
.
printf
(
"%.3f °C = %.3f °F\n"
,
c
,
wynik
);
}
default
->
{
System
.
out
.
println
(
"Nieznane polecenie "
+
wybor
);
}
}
}
System
.
out
.
println
(
"Dzięki, miłego dnia!"
);
}
}
\ No newline at end of file
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