Created
December 14, 2018 14:41
-
-
Save hannojg/ebd434c87388e85eed2f17afe89b92d1 to your computer and use it in GitHub Desktop.
Verwaltung von Mitarbeitern und Studenten der Uni: UML zu Java, Loesung
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Druckbar { | |
public void drucken(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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