Skip to content

Instantly share code, notes, and snippets.

@hannojg
Created December 14, 2018 14:41
Show Gist options
  • Save hannojg/ebd434c87388e85eed2f17afe89b92d1 to your computer and use it in GitHub Desktop.
Save hannojg/ebd434c87388e85eed2f17afe89b92d1 to your computer and use it in GitHub Desktop.
Verwaltung von Mitarbeitern und Studenten der Uni: UML zu Java, Loesung
public class Angestellter extends Person {
private double gehalt;
private String abteilung;
public Angestellter(String name, String vorname) {
super(name, vorname);
}
public double getGehalt() {
return gehalt;
}
public boolean hatUrlaub() {
return true;
}
public void setAbteilung(String bezeichnung) {
this.abteilung = bezeichnung;
}
public void drucken() {
System.out.print(
super.vorname + " " + getName() + "\n"
+ "E-Mail-Adresse: " + super.email + "\n"
+ "arbeitet in Abteilung " + abteilung + ".\n"
);
}
}
public interface Druckbar {
public void drucken();
}
public abstract class Person implements Druckbar {
protected String name;
protected String vorname;
protected String email = "";
public Person(String name, String vorname) {
this.name = name;
this.vorname = vorname;
}
public abstract boolean hatUrlaub();
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
}
public class Student extends Person {
private static int naechsteMatrNr = 9999;
private int matrNr;
private int semester;
public Student(String name, String vorname, int semester) {
super(name, vorname);
this.semester = semester;
}
public static int getNaechsteMatrNr() {
return ++naechsteMatrNr;
}
public int getSemester() {
return semester;
}
public void setSemester(int semester) {
this.semester = semester;
}
public boolean hatUrlaub() {
return false;
}
public void drucken() {
System.out.print(
super.vorname + " " + getName() + "\n"
+ "E-Mail-Adresse: " + super.email + "\n"
+ "Matrikelnummer " + getNaechsteMatrNr() + "\n"
+ "im " + getSemester() + ". Semester." + "\n"
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment