Hallo.
Ich hätte da nochmal ne Frage bzgl. meines Programms.
Ich habe nun die Class Person erstellt, die wie folgt aussieht:
Weiteres hab ich eine Class WaitingRoom, die so aussieht:
Ich muss nun noch folgenden Fall beachten:
Der Warteraum ist leer, aber der Doktor ruft "Der nächste bitte"
Wie sichert man dies?
Ich benötige auch noch die Methoden:
-public int getNumberofPersons()
-public Person nextPerson()
Wie wird das im besten Fall implementiert? Bitte um schnelle Hilfe.
Vielen Dank schon mal.
Ganz liebe Grüße
Ich hätte da nochmal ne Frage bzgl. meines Programms.
Ich habe nun die Class Person erstellt, die wie folgt aussieht:
Code:
public class Person {
private String firstname;
private String lastname;
private String socialSecurityNumber;
public Person(String socialSecurityNumber)
{
this.socialSecurityNumber = socialSecurityNumber;
}
public Person(String firstname, String lastname, String socialSecurityNumber)
{
this.firstname = firstname;
this.lastname = lastname;
this.socialSecurityNumber = socialSecurityNumber;
}
public void getFirstname() {
System.out.println(firstname);
}
public void getLastname() {
System.out.println(lastname);
}
public void getSocialSecurityNumber() {
System.out.println(socialSecurityNumber);
}
public void setFirstName(String firstname) {
this.firstname = firstname;
}
public void setLastName (String lastname) {
this.lastname = lastname;
}
}
Weiteres hab ich eine Class WaitingRoom, die so aussieht:
Code:
import java.util.Queue;
import java.util.LinkedList;
public class WaitingRoom {
public Queue<Person> queue;
private final int capacity;
public WaitingRoom(int capacity) {
this.queue = new LinkedList<Person>();
this.capacity = capacity;
}
public boolean isFull() {
if (queue.size() == capacity) {
return true;
} else {
return false;
}
}
public boolean isEmpty() {
if (queue.size() != capacity) {
return true;
} else {
return false;
}
}
public int getCapacity() {
return this.capacity;
}
public void enter(Person person) {
if (queue.size() == capacity) {
System.out.println("The waitingroom is temporarely overcrowded!");
} else {
queue.add(person);
}
}
}
Ich muss nun noch folgenden Fall beachten:
Der Warteraum ist leer, aber der Doktor ruft "Der nächste bitte"
Wie sichert man dies?
Ich benötige auch noch die Methoden:
-public int getNumberofPersons()
-public Person nextPerson()
Wie wird das im besten Fall implementiert? Bitte um schnelle Hilfe.
Vielen Dank schon mal.
Ganz liebe Grüße