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
1d189722
Commit
1d189722
authored
Apr 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Konto - pierwsza wersja
parent
f135c443
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
3 deletions
+59
-3
Konto.java
src/p11_klasy/enkapsulacja/Konto.java
+48
-0
Program.java
src/p11_klasy/enkapsulacja/Program.java
+11
-3
No files found.
src/p11_klasy/enkapsulacja/Konto.java
0 → 100644
View file @
1d189722
package
p11_klasy
.
enkapsulacja
;
public
class
Konto
{
private
final
int
numer
;
private
int
saldo
;
private
Osoba
wlasciciel
;
public
Konto
(
int
numer
,
int
saldo
,
Osoba
wlasciciel
)
{
this
.
numer
=
numer
;
this
.
saldo
=
saldo
;
this
.
wlasciciel
=
wlasciciel
;
}
@Override
public
String
toString
()
{
return
"Konto nr "
+
numer
+
", saldo "
+
saldo
+
" wł. "
+
wlasciciel
;
}
// Dla pola numer nie tworzę settera, gdyż numer konta się nie zmienia.
// Dodatkowo jest to zapewnione modyfikatorem final.
// Dla pola saldo nie tworzę settera, gdyż salda nie ustawia się "bez żadnego trybu",
// tylko saldo można zmodyfikować poprzez operacje biznesowe: wplata, wyplata, przelew.
public
int
getNumer
()
{
return
numer
;
}
public
int
getSaldo
()
{
return
saldo
;
}
public
Osoba
getWlasciciel
()
{
return
wlasciciel
;
}
public
void
setWlasciciel
(
Osoba
wlasciciel
)
{
this
.
wlasciciel
=
wlasciciel
;
}
public
void
wplata
(
int
kwota
)
{
this
.
saldo
+=
kwota
;
}
public
void
wyplata
(
int
kwota
)
{
this
.
saldo
-=
kwota
;
}
}
src/p11_klasy/enkapsulacja/Program.java
View file @
1d189722
...
...
@@ -26,9 +26,17 @@ public class Program {
// próba modyfikacji listy za pośrednictwem gettera
List
<
Integer
>
lista
=
student
.
getOceny
();
System
.
out
.
println
(
lista
);
lista
.
removeIf
(
x
->
x
<
4
);
// usuń wszystkie oceny gorsze niż 4 - w wersji unmodifiable wyrzuca wyjątek
System
.
out
.
println
(
lista
);
System
.
out
.
println
(
"średnia: "
+
student
.
sredniaOcen
());
// lista.removeIf(x -> x < 4); // usuń wszystkie oceny gorsze niż 4 - w wersji unmodifiable wyrzuca wyjątek
// System.out.println(lista);
// System.out.println("średnia: " + student.sredniaOcen());
System
.
out
.
println
();
Konto
konto1
=
new
Konto
(
1
,
1000
,
ala
);
System
.
out
.
println
(
konto1
);
konto1
.
wplata
(
300
);
System
.
out
.
println
(
konto1
);
konto1
.
wyplata
(
400
);
System
.
out
.
println
(
konto1
);
}
}
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