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
849f89a0
Commit
849f89a0
authored
Apr 12, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
poprawka wersji z tablicą
parent
7c8ed1bf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
Program.java
src/p11_klasy/enkapsulacja/Program.java
+5
-0
Student.java
src/p11_klasy/enkapsulacja/Student.java
+8
-2
No files found.
src/p11_klasy/enkapsulacja/Program.java
View file @
849f89a0
...
@@ -18,6 +18,11 @@ public class Program {
...
@@ -18,6 +18,11 @@ public class Program {
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
5
);
student
.
dodajOcene
(
5
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
5
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
3
);
student
.
dodajOcene
(
4
);
System
.
out
.
println
(
"oceny: "
+
student
.
getOceny
());
System
.
out
.
println
(
"oceny: "
+
student
.
getOceny
());
System
.
out
.
println
(
"średnia: "
+
student
.
sredniaOcen
());
System
.
out
.
println
(
"średnia: "
+
student
.
sredniaOcen
());
}
}
...
...
src/p11_klasy/enkapsulacja/Student.java
View file @
849f89a0
...
@@ -2,6 +2,7 @@ package p11_klasy.enkapsulacja;
...
@@ -2,6 +2,7 @@ package p11_klasy.enkapsulacja;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
public
class
Student
extends
Osoba
{
public
class
Student
extends
Osoba
{
...
@@ -36,8 +37,13 @@ public class Student extends Osoba {
...
@@ -36,8 +37,13 @@ public class Student extends Osoba {
}
}
public
void
dodajOcene
(
int
ocena
)
{
public
void
dodajOcene
(
int
ocena
)
{
oceny
[
liczbaOcen
]
=
ocena
;
// ważny schemat w programowaniu, używany m.in. przez klasy ArrayList, StringBuilder
liczbaOcen
++;
// gdy w tablicy brakuje miejsca, tworzymy nową tablicę 2x większą i kopiujemy do niej elementy
if
(
liczbaOcen
==
oceny
.
length
)
{
System
.
out
.
println
(
"powiększanie tablicy"
);
oceny
=
Arrays
.
copyOf
(
oceny
,
2
*
oceny
.
length
);
}
oceny
[
liczbaOcen
++]
=
ocena
;
}
}
public
List
<
Integer
>
getOceny
()
{
public
List
<
Integer
>
getOceny
()
{
...
...
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