Soll-Lösung Klausur 24.04.2026
Erst selbst lösen! Dann hier vergleichen.
Attendee (Interface)
public interface Attendee {
Ticket getTicket();
}
Information
public class Information {
private String stockwerk;
private String raum;
public Information(String stockwerk, String raum) {
this.stockwerk = stockwerk;
this.raum = raum;
}
public boolean isComplete() {
if (stockwerk != null && raum != null) {
return true;
} else {
return false;
}
}
}
Ticket
public class Ticket {
private final String name;
private final boolean isVip;
public Ticket(String name, boolean isVip) {
this.name = name;
this.isVip = isVip;
}
public String getName() { return name; }
public boolean isVip() { return isVip; }
}
Professional
public class Professional implements Attendee {
public final String name;
public final Ticket ticket;
public Professional(String name) {
this.name = name;
this.ticket = new Ticket("ALLACCESS", true);
}
@Override
public Ticket getTicket() { return ticket; }
}
Student
public class Student implements Attendee {
public final String name;
public final Ticket ticket;
public Student(String name, Ticket ticket) {
this.name = name;
this.ticket = ticket;
}
@Override
public Ticket getTicket() { return ticket; }
}
Room (abstract)
import java.util.ArrayList;
public abstract class Room implements Comparable<Room> {
private static final ArrayList<Room> ROOMS = new ArrayList<>();
public final int floor;
public final int maxAttendees;
protected ArrayList<Attendee> attendees;
public Room(int floor, int maxAttendees) {
this.floor = floor;
this.maxAttendees = maxAttendees;
this.attendees = new ArrayList<>();
ROOMS.add(this);
}
protected boolean isFree() {
if (attendees.size() < maxAttendees) {
return true;
} else {
return false;
}
}
public void enter(Attendee a) throws NotAllowedException {
if (isFree()) {
this.attendees.add(a);
} else {
throw new NotAllowedException("Raum ist voll", this);
}
}
@Override
public int compareTo(Room other) {
if (this.attendees.size() > other.attendees.size()) return -1;
else if (this.attendees.size() < other.attendees.size()) return 1;
else return 0;
}
}
LectureHall
public class LectureHall extends Room {
private static final int MAX_20 = 20;
private Professional speaker;
public LectureHall(int floor) {
super(floor, MAX_20);
}
private boolean isSpeakerPresent() {
if (speaker == null) {
return false;
} else {
return true;
}
}
@Override
public void enter(Attendee a) throws NotAllowedException {
if (isSpeakerPresent() && a instanceof Professional) {
throw new NotAllowedException("Speaker ist schon da", this);
}
if (a instanceof Professional) {
this.speaker = (Professional) a;
}
super.enter(a);
}
}
BlockedRoom
public class BlockedRoom extends Room {
public BlockedRoom(int floor) {
super(floor, 0);
}
@Override
public void enter(Attendee a) throws NotAllowedException {
throw new NotAllowedException("Raum ist blockiert", this);
}
}
MeetingRoom
public class MeetingRoom extends Room {
public final String subject;
public MeetingRoom(int floor, String subject) {
super(floor, 8);
this.subject = subject;
}
@Override
public void enter(Attendee a) throws NotAllowedException {
Ticket t = a.getTicket();
if (t.isVip() || "ALLACCESS".equals(t.getName())) {
super.enter(a);
} else {
throw new NotAllowedException("Ticket nicht gültig oder nicht vorhanden", this);
}
}
}
ConferenceCenter
import java.util.ArrayList;
public class ConferenceCenter {
public final String name;
public final ArrayList<Room> rooms;
public ConferenceCenter(String name) {
this(name, 4);
}
public ConferenceCenter(String name, int numberOfFloors) {
this.name = name;
this.rooms = new ArrayList<>();
for (int i = 0; i < numberOfFloors; i++) {
if (i == 2 || i == 4 || i == 6) {
rooms.add(new LectureHall(i));
} else {
rooms.add(new MeetingRoom(i, "Meetingraum"));
}
}
}
}
ExamTask
public class ExamTask {
public static void main(String[] args) {
ConferenceCenter cc = new ConferenceCenter("DHBW");
Professional dozent = new Professional("Steffen");
Student lolli = new Student("Lolli", new Ticket("VIP", true));
for (Room r : cc.rooms) {
try {
r.enter(dozent);
r.enter(lolli);
} catch (NotAllowedException e) {
System.out.println(e.getMessage());
}
}
}
}
NotAllowedException
public class NotAllowedException extends Exception {
public final Room room;
public NotAllowedException(String message, Room room) {
super(message);
this.room = room;
}
}