Commit bcfc1387 by Patryk Czarnik

obsługa ocen

parent 4a674a2a
......@@ -21,11 +21,17 @@ public class PrzykladDziedziczenie {
student.przedstawSie();
student.dodajOcene(4);
student.dodajOcene(4);
student.dodajOcene(5);
System.out.println("Średnia ocen: " + student.sredniaOcen());
// Obiekt klasy Student "jest" jednocześnie obiektem klasy Osoba
// i może być użyty wszędzie tam, gdzie oczekiwana jest jakaś Osoba.
Sklep zabka = new Sklep("Żabka", 6);
zabka.sprzedajPiwo(student);
Konto kontoStudenckie = new Konto(1, 1000, student);
System.out.println(kontoStudenckie);
}
}
package p10_klasy.v4;
import java.util.ArrayList;
import java.util.List;
public class Student extends Osoba {
int rok;
String kierunek;
List<Integer> oceny = new ArrayList<>();
void dodajOcene(int ocena) {
// TODO
oceny.add(ocena);
}
double sredniaOcen() {
return 4.5;
double suma = 0;
for(int ocena : oceny) {
suma += ocena;
}
return suma / oceny.size();
}
}
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