Commit 18bf1a05 by Patryk Czarnik

pierwsze zmiany w widoczoności - work in progress :)

parent 96d12e94
package p10_klasy.v5; package p10_klasy.v5;
public class Osoba { public class Osoba {
String imie, nazwisko; protected String imie, nazwisko;
int wiek; protected int wiek;
Osoba() { Osoba() {
} }
......
...@@ -5,14 +5,17 @@ public class Przyklad { ...@@ -5,14 +5,17 @@ public class Przyklad {
public static void main(String[] args) { public static void main(String[] args) {
Osoba osoba = new Osoba("Ala", "Kowalska", 30); Osoba osoba = new Osoba("Ala", "Kowalska", 30);
osoba.przedstawSie(); osoba.przedstawSie();
System.out.println("Imię i nazwisko: " + osoba.imie + " " + osoba.nazwisko); // System.out.println("Imię i nazwisko: " + osoba.imie + " " + osoba.nazwisko);
// osoba.imie = "Alicja";
osoba.przedstawSie();
Student student = new Student("Adam", "Abacki", 21, 2, "medycyna"); Student student = new Student("Adam", "Abacki", 21, 2, "medycyna");
student.przedstawSie(); student.przedstawSie();
student.dodajOcene(4); student.dodajOcene(4);
student.dodajOcene(4); student.dodajOcene(4);
student.dodajOcene(5); student.dodajOcene(5);
student.oceny.add(100); //NK student.oceny.add(100);
student.dodajOcene(100);
System.out.println("Średnia ocen: " + student.sredniaOcen()); System.out.println("Średnia ocen: " + student.sredniaOcen());
Sklep zabka = new Sklep("Żabka", 6); Sklep zabka = new Sklep("Żabka", 6);
......
...@@ -6,7 +6,7 @@ import java.util.List; ...@@ -6,7 +6,7 @@ import java.util.List;
public class Student extends Osoba { public class Student extends Osoba {
int rok; int rok;
String kierunek; String kierunek;
List<Integer> oceny = new ArrayList<>(); private List<Integer> oceny = new ArrayList<>();
Student() { Student() {
} }
...@@ -25,7 +25,11 @@ public class Student extends Osoba { ...@@ -25,7 +25,11 @@ public class Student extends Osoba {
// 2) Dodać nowe metody, których nie było w nadklasie // 2) Dodać nowe metody, których nie było w nadklasie
void dodajOcene(int ocena) { void dodajOcene(int ocena) {
oceny.add(ocena); if(ocena >= 2 && ocena <= 5) {
oceny.add(ocena);
} else {
System.err.println("błędna ocena " + ocena);
}
} }
double sredniaOcen() { double sredniaOcen() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment