Commit 18bf1a05 by Patryk Czarnik

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

parent 96d12e94
package p10_klasy.v5;
public class Osoba {
String imie, nazwisko;
int wiek;
protected String imie, nazwisko;
protected int wiek;
Osoba() {
}
......
......@@ -5,14 +5,17 @@ public class Przyklad {
public static void main(String[] args) {
Osoba osoba = new Osoba("Ala", "Kowalska", 30);
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.przedstawSie();
student.dodajOcene(4);
student.dodajOcene(4);
student.dodajOcene(5);
student.oceny.add(100);
//NK student.oceny.add(100);
student.dodajOcene(100);
System.out.println("Średnia ocen: " + student.sredniaOcen());
Sklep zabka = new Sklep("Żabka", 6);
......
......@@ -6,7 +6,7 @@ import java.util.List;
public class Student extends Osoba {
int rok;
String kierunek;
List<Integer> oceny = new ArrayList<>();
private List<Integer> oceny = new ArrayList<>();
Student() {
}
......@@ -25,7 +25,11 @@ public class Student extends Osoba {
// 2) Dodać nowe metody, których nie było w nadklasie
void dodajOcene(int ocena) {
if(ocena >= 2 && ocena <= 5) {
oceny.add(ocena);
} else {
System.err.println("błędna ocena " + ocena);
}
}
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