Skip to content
Snippets Groups Projects
Commit 7f4e7e49 authored by Paul Rauser's avatar Paul Rauser
Browse files

chore: build clean and readable solution

parent be6ec405
No related branches found
No related tags found
No related merge requests found
/bin
\ No newline at end of file
......@@ -7,7 +7,7 @@
**Dauer**: < 45 Minuten
## Aufgabenstellung
Schreiben Sie ein Modell, welches Professoren, Assistenten und Fakultäten verwaltet. Mittels der Fakultät sollte eine Menge an Fragen beanwortet werden können.
Schreiben Sie ein Modell, welches Professoren, Assistenten und Fakultäten verwaltet. Mittels des Modells soll eine Menge an Fragen beanwortet werden können.
### Grundlegende Informationen:
- Ein Professor hat:
......@@ -28,7 +28,7 @@ Schreiben Sie ein Modell, welches Professoren, Assistenten und Fakultäten verwa
- hat einen Namen
- besteht aus Professoren und Assistenten.
### Fragestellungen an die Fakultät:
### Fragestellungen an das Modell:
1. Welche Assistenten sind einem bestimmten Professor zugeordnet?
2. Welche Professoren haben einen Assistenten?
......
......@@ -4,57 +4,39 @@ public class App {
public static void main(String[] args) {
// Setup
Faculty inf = new Faculty("Informatik");
Professor prof1 = new Professor("Prof. A", 45, "Cloud Computing", inf);
Professor prof2 = new Professor("Prof. B", 52, "Cyber Security", inf);
Professor prof3 = new Professor("Prof. C", 43, "Cyber Security", inf);
Assistant assistant1 = new Assistant("Assistant 1", 24, inf);
Assistant assistant2 = new Assistant("Assistant 2", 24, inf);
Assistant assistant3 = new Assistant("Assistant 3", 26, inf);
assistant1.setBoss(prof1);
assistant2.setBoss(prof1);
assistant3.setBoss(prof2);
inf.addAssistant(assistant1);
inf.addAssistant(assistant2);
inf.addAssistant(assistant3);
inf.addProfessor(prof1);
inf.addProfessor(prof2);
inf.addProfessor(prof3);
// Question 1 - How many Assistants for specific professor
System.out.println(prof1.getName() + " has " + inf.getAssistantsOfProf(prof1).size() + " assistants");
System.out.println(prof2.getName() + " has " + inf.getAssistantsOfProf(prof2).size() + " assistants");
// Question 2 - Which professors have an assistant
System.out.println("All profs with assistants: " + inf.getProfsWithAssistants());
// Question 3 - How many professors are in a faculty
System.out.println("There are " + inf.getAmountOfProfs() + " profs in the faculty");
// Question 4 - How many assistants are in a faculty?
System.out.println("There are " + inf.getAmountOfAssistants() + " assistants in the faculty");
// Question 5 - How many research areas are there?
Faculty hogwarts = new Faculty("Hogwarts");
Professor dumbledore = new Professor("Dumbledore", 77, "BPM", hogwarts);
System.out.println(dumbledore.getName());
System.out.println("Hält er Vorlesung? "+dumbledore.isLecturing());
dumbledore.setLecturing(false);
System.out.println("Hält er Vorlesung? "+dumbledore.isLecturing());
Assistent hagrid = new Assistent("Hagrid", 26, hogwarts);
hagrid.setBoss(dumbledore);
System.out.println(hagrid.getName());
System.out.println(hagrid.getBoss().getName());
Assistent dobby = new Assistent("Dobby", 130, hogwarts);
dobby.setBoss(dumbledore);
Assistent pince = new Assistent("Madam Pince", 50, hogwarts);
hogwarts.addProfessor(dumbledore);
hogwarts.addAssistent(hagrid);
hogwarts.addAssistent(dobby);
hogwarts.addAssistent(pince);
System.out.println("Fakultät "+ hogwarts.getName());
System.out.println(hogwarts.getProfs().toString());
System.out.println(hogwarts.getAssis().toString());
System.out.println(hogwarts.getAssisOfProf(dumbledore));
System.out.println(hogwarts.getProfsWithAssis());
System.out.println("Anzahl Profs: " + hogwarts.getAmountProfs());
System.out.println("Anzahl Assis: " + hogwarts.getAmountAssis());
System.out.println("There are " + inf.getNumberOfResearchAreas() + " research areas");
}
}
package campus;
public class Assistent {
public class Assistant {
private String name;
private int age;
private Professor boss;
private Faculty faculty;
public Assistent(String name, int age, Faculty faculty) {
public Assistant(String name, int age, Faculty faculty) {
this.name=name;
this.age=age;
this.faculty = faculty;
......
......@@ -5,11 +5,11 @@ import java.util.ArrayList;
public class Faculty {
private String name;
private ArrayList<Professor> profs;
private ArrayList<Assistent> assis;
private ArrayList<Assistant> assistants;
public Faculty(String name) {
this.name = name;
this.assis = new ArrayList<Assistent>();
this.assistants = new ArrayList<Assistant>();
this.profs = new ArrayList<Professor>();
}
......@@ -22,51 +22,60 @@ public class Faculty {
profs.add(professor);
}
public void addAssistent(Assistent assistent) {
if (!assis.contains(assistent))
assis.add(assistent);
public void addAssistant(Assistant assistant) {
if (!assistants.contains(assistant))
assistants.add(assistant);
}
public ArrayList<Professor> getProfs() {
return profs;
}
public ArrayList<Assistent> getAssis() {
return assis;
public ArrayList<Assistant> getAssistants() {
return assistants;
}
public ArrayList<Assistent> getAssisOfProf(Professor professor) {
ArrayList<Assistent> profassis = new ArrayList<>();
public ArrayList<Assistant> getAssistantsOfProf(Professor professor) {
ArrayList<Assistant> profAssistants = new ArrayList<>();
if (!profs.contains(professor)) {
return profassis;
return profAssistants;
}
for (Assistent assi : assis) {
Professor p = assi.getBoss();
for (Assistant assistant : assistants) {
Professor p = assistant.getBoss();
if (p != null && p.equals(professor)) {
profassis.add(assi);
profAssistants.add(assistant);
}
}
return profassis;
return profAssistants;
}
public ArrayList<Professor> getProfsWithAssis() {
ArrayList<Professor> profsWithAssis = new ArrayList<>();
for (Assistent assi : assis) {
Professor p = assi.getBoss();
if (p != null && !profsWithAssis.contains(p)) {
profsWithAssis.add(p);
public ArrayList<Professor> getProfsWithAssistants() {
ArrayList<Professor> profsWithAssistants = new ArrayList<>();
for (Assistant assistant : assistants) {
Professor p = assistant.getBoss();
if (p != null && !profsWithAssistants.contains(p)) {
profsWithAssistants.add(p);
}
}
return profsWithAssis;
return profsWithAssistants;
}
public int getAmountProfs() {
public int getNumberOfResearchAreas() {
ArrayList<String> researchAreas = new ArrayList<>();
for(Professor prof : profs) {
String researchArea = prof.getResearchArea();
if(!researchAreas.contains(researchArea)) researchAreas.add(researchArea);
}
return researchAreas.size();
}
public int getAmountOfProfs() {
return profs.size();
}
public int getAmountAssis() {
return assis.size();
public int getAmountOfAssistants() {
return assistants.size();
}
}
\ No newline at end of file
......@@ -3,26 +3,16 @@ package campus;
public class Professor {
private String name;
private int age;
private boolean isLecturing;
private String researchArea;
private Faculty faculty;
public Professor(String name, int age, String researchArea, Faculty faculty) {
this.name = name;
this.age = age;
this.isLecturing = true;
this.researchArea = researchArea;
this.faculty = faculty;
}
public void setLecturing(boolean isLecturing) {
this.isLecturing = isLecturing;
}
public boolean isLecturing() {
return isLecturing;
}
public String getName() {
return name;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment