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
af3d469a
Commit
af3d469a
authored
Apr 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ProgramBankowy
parent
1d189722
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
Program.java
src/p11_klasy/enkapsulacja/Program.java
+3
-0
ProgramBankowy.java
src/p11_klasy/enkapsulacja/ProgramBankowy.java
+65
-0
No files found.
src/p11_klasy/enkapsulacja/Program.java
View file @
af3d469a
...
...
@@ -37,6 +37,9 @@ public class Program {
System
.
out
.
println
(
konto1
);
konto1
.
wyplata
(
400
);
System
.
out
.
println
(
konto1
);
konto1
.
wplata
(-
2000
);
System
.
out
.
println
(
konto1
);
}
}
src/p11_klasy/enkapsulacja/ProgramBankowy.java
0 → 100644
View file @
af3d469a
package
p11_klasy
.
enkapsulacja
;
import
java.util.Scanner
;
public
class
ProgramBankowy
{
public
static
void
main
(
String
[]
args
)
{
@SuppressWarnings
(
"resource"
)
Scanner
sc
=
new
Scanner
(
System
.
in
);
Osoba
ala
=
new
Osoba
(
"Ala"
,
"Kowalska"
,
"1985-05-05"
);
System
.
out
.
print
(
"Podaj początkową kwotę: "
);
int
kwota
=
sc
.
nextInt
();
sc
.
nextLine
();
// wymuszenie przejścia do nowej linii
Konto
konto
=
new
Konto
(
1
,
kwota
,
ala
);
System
.
out
.
println
(
konto
);
petla:
while
(
true
)
{
try
{
System
.
out
.
println
(
"Co chcesz zrobić? W - wpłata, Y - wypłata, K - koniec"
);
String
wybor
=
sc
.
nextLine
().
toUpperCase
();
switch
(
wybor
)
{
case
"K"
,
"Q"
->
{
break
petla
;
// przejście do Koniec programu
}
case
"W"
->
{
System
.
out
.
print
(
"Podaj kwotę wpłaty: "
);
kwota
=
sc
.
nextInt
();
sc
.
nextLine
();
konto
.
wplata
(
kwota
);
System
.
out
.
println
(
"Pieniądze zostały wpłacone"
);
}
case
"Y"
->
{
System
.
out
.
print
(
"Podaj kwotę wypłaty: "
);
kwota
=
sc
.
nextInt
();
sc
.
nextLine
();
konto
.
wyplata
(
kwota
);
// ta linia wykona się tylko jeśli nie było wyjątku:
System
.
out
.
println
(
"Pieniądze zostały wypłacone"
);
}
default
->
{
System
.
out
.
println
(
"Nieznane polecenie"
);
continue
petla
;
// Przejście do Co chcesz zrobić
}
}
// Jeśli o różnych sytuacjach błędnych będą informować wyjątki różnych klas,
// to w programie możemy te sytuacje rozróżnić i obsłużyć w róznych catchach
}
catch
(
IllegalArgumentException
e
)
{
System
.
out
.
println
(
"Niepoprawny argument: "
+
e
.
getMessage
());
// } catch(BrakSrodkow e) {
// System.out.println(e.getMessage());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Inny błąd: "
+
e
);
}
System
.
out
.
println
();
System
.
out
.
println
(
konto
);
System
.
out
.
println
();
}
System
.
out
.
println
(
"Koniec programu"
);
}
}
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