diff --git a/src/shoes/.gitkeep b/src/shoes/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/shoes/App.java b/src/shoes/App.java deleted file mode 100644 index d87b89ef2d1b28989465ff68c186d80872a0b0fd..0000000000000000000000000000000000000000 --- a/src/shoes/App.java +++ /dev/null @@ -1,58 +0,0 @@ -package shoes; - -public class App { - public static void main(String[] args) throws BoxException { - Sneakers sneakers = new Sneakers("Blue Sneakers", 42.5); - Sneakers sneakers2 = new Sneakers("White Sneakers", 44.0); - Boots boots = new Boots("Brown Boots", 39.0); - Boots boots2 = new Boots("Black Boots", 37.5); - - ShoeBox<Boots> sb1 = new ShoeBox<>(); - ShoeBox<Sneakers> sb2 = new ShoeBox<>(); - ShoeBox<Boots> sb3 = new ShoeBox<>(); - ShoeBox<Sneakers> sb4 = new ShoeBox<>(); - - sb1.putObjectInBox(boots); - sb2.putObjectInBox(sneakers); - sb3.putObjectInBox(boots2); - sb4.putObjectInBox(sneakers2); - - System.out.println(sb1); - System.out.println(sb2); - System.out.println("\n_____________________________________________\n"); - - // task d) - System.out.println("Create shelf with x=3 y=5"); - Shelf shelf = new Shelf(3,5); - - System.out.println("Leeres Regal:\n"+shelf); - - //Adding boxes to shelf - System.out.println("Add sb1 to 0/4"); - shelf.addBox(0,4,sb1); - System.out.println("Add sb2 to 2/2"); - shelf.addBox(2,2,sb2); - System.out.println("Add sb3 to 0/1"); - shelf.addBox(0,1,sb3); - System.out.println("Add sb4 to 2/1"); - shelf.addBox(2,1,sb4); - - System.out.println("\nContents of shelf:"); - System.out.println(shelf); - - //shelf.addBox(42, 32, sb1); //IndexOutOfBoundsException - //System.out.println("Add sb2 to 2/2 to throw an Exception"); - //shelf.addBox(2,2,sb2); //Exception - - //Removing boxes from shelf - System.out.println("Remove Box from 2/2"); - shelf.removeBox(2, 2); - - //shelf.removeBox(3, 5); //IndexOutOfBoundsException - //System.out.println("Remove Box from 2/2 to throw an Exception"); - //shelf.removeBox(2, 2); //Exception - - System.out.println("\nContents of shelf after removing:"); - System.out.println(shelf); - } -} diff --git a/src/shoes/Boots.java b/src/shoes/Boots.java deleted file mode 100644 index 152d834d927366e71a4728920486df45b338dc13..0000000000000000000000000000000000000000 --- a/src/shoes/Boots.java +++ /dev/null @@ -1,7 +0,0 @@ -package shoes; - -public class Boots extends Shoes { - public Boots(String name, double size) { - super(name, size); - } -} diff --git a/src/shoes/Box.java b/src/shoes/Box.java deleted file mode 100644 index f54f67d4b6fd26704c271d6884aa1544e0190236..0000000000000000000000000000000000000000 --- a/src/shoes/Box.java +++ /dev/null @@ -1,36 +0,0 @@ -package shoes; - -public abstract class Box<T> { - private T content; - - public Box() { - super(); - } - - public Box(T content) { - this.content = content; - } - - public void putObjectInBox(T obj) throws BoxException { - if (content == null) { - content = obj; - } else { - throw new BoxException("Box is full!"); - } - } - - public T removeObjectInBox() { - T temp = content; - content = null; - return temp; - } - - public T getObjectInBox() { - return content; - } - - @Override - public String toString() { - return "[" + content + "]"; - } -} \ No newline at end of file diff --git a/src/shoes/BoxException.java b/src/shoes/BoxException.java deleted file mode 100644 index 2e03a289b04b9c281227ea4d8991226da5d9710a..0000000000000000000000000000000000000000 --- a/src/shoes/BoxException.java +++ /dev/null @@ -1,7 +0,0 @@ -package shoes; - -public class BoxException extends Exception { - public BoxException(String msg) { - super(msg); - } -} diff --git a/src/shoes/Shelf.java b/src/shoes/Shelf.java deleted file mode 100644 index 9b9a7f068c30160a8cddc979b59d7ed030478871..0000000000000000000000000000000000000000 --- a/src/shoes/Shelf.java +++ /dev/null @@ -1,55 +0,0 @@ -package shoes; - -import java.util.ArrayList; -import java.util.List; - -public class Shelf { - private ArrayList<ArrayList<ShoeBox<? extends Shoes>>> shelf; - private int height; - private int width; - - public Shelf(int height, int width) { - this.height = height; - this.width = width; - shelf = new ArrayList<>(); - for (int i = 0; i < height; i++) { - shelf.add(new ArrayList<ShoeBox<? extends Shoes>>()); - for (int j = 0; j < width; j++) { - shelf.get(i).add(null); // add empty slots - } - } - } - - public void addBox(int x, int y, ShoeBox<? extends Shoes> box) throws BoxException { - if (x < 0 || y < 0 || x >= this.height || y >= this.width) - throw new IndexOutOfBoundsException("There is no such place in the shelf!"); - if (shelf.get(x).get(y) != null) - throw new BoxException("There is already a different box in " + x + "/" + y + "!"); - shelf.get(x).set(y, box); - } - - public void removeBox(int x, int y) throws BoxException { - if (x < 0 || y < 0 || x >= this.height || y >= this.width) - throw new IndexOutOfBoundsException("There is no such place in the shelf!"); - if (shelf.get(x).get(y) == null) - throw new BoxException("No item to remove in " + x + "/" + y + "!"); - shelf.get(x).set(y, null); - } - - public ShoeBox<? extends Shoes> get(int x, int y) { - return shelf.get(x).get(y); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - for (List<ShoeBox<? extends Shoes>> shelfY : shelf) { - for (ShoeBox<? extends Shoes> box : shelfY) { - sb.append("|" + (box == null ? "----free----" : box.toString()) + "|"); - } - sb.append('\n'); - - } - return sb.toString(); - } -} diff --git a/src/shoes/ShoeBox.java b/src/shoes/ShoeBox.java deleted file mode 100644 index a6d6a2986962ea1e588550681ef0fb9d89c3095e..0000000000000000000000000000000000000000 --- a/src/shoes/ShoeBox.java +++ /dev/null @@ -1,11 +0,0 @@ -package shoes; - -public class ShoeBox<T extends Shoes> extends Box<T> { - public ShoeBox() { - super(); - } - - public ShoeBox(T content) { - super(content); - } -} diff --git a/src/shoes/Shoes.java b/src/shoes/Shoes.java deleted file mode 100644 index 5db623a35184cf3fcdee114b1fb01272b1d01f0b..0000000000000000000000000000000000000000 --- a/src/shoes/Shoes.java +++ /dev/null @@ -1,16 +0,0 @@ -package shoes; - -public abstract class Shoes { - private String name; - private double size; - - public Shoes (String name, double size) { - this.name = name; - this.size = size; - } - - @Override - public String toString() { - return "{" + name + ", " + size + "}"; - } -} diff --git a/src/shoes/Sneakers.java b/src/shoes/Sneakers.java deleted file mode 100644 index 81011f36bff31766beeaf8fa2fb351415cacc44a..0000000000000000000000000000000000000000 --- a/src/shoes/Sneakers.java +++ /dev/null @@ -1,7 +0,0 @@ -package shoes; - -public class Sneakers extends Shoes { - public Sneakers(String name, double size) { - super(name, size); - } -}