diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..bfbeb0d --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,3 @@ +{ + "image": "mcr.microsoft.com/devcontainers/java:21" +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..add4f4e --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack" + ] +} \ No newline at end of file diff --git a/Exercise.java b/Exercise.java index 3c092f9..bdc297e 100644 --- a/Exercise.java +++ b/Exercise.java @@ -1,6 +1,14 @@ public class Exercise { public static void main(String[] args) { - // implement exercise here + House house = new House(); + + house.addRoom(house.new Room("Wohnzimmer")); + house.addRoom(house.new Room("Esszimmer")); + house.addRoom(house.new Room("Schlafzimmer")); + house.addRoom(house.new Room("Kueche")); + house.addRoom(house.new Room("WC")); + + house.displayRooms(); } } diff --git a/House.java b/House.java new file mode 100644 index 0000000..e4088b8 --- /dev/null +++ b/House.java @@ -0,0 +1,33 @@ +import java.util.ArrayList; + +public class House { + + private ArrayList rooms; + + public House() { + rooms = new ArrayList<>(); + } + + public void addRoom(Room room) { + rooms.add(room); + } + + public void displayRooms() { + for (Room r : rooms) { + r.displayRoom(); + } + } + + public class Room { + + private String name; + + public Room(String name) { + this.name = name; + } + + public void displayRoom() { + System.out.println(name); + } + } +}