From 6a771312d296a67ac7bced1742df22957f90d43b Mon Sep 17 00:00:00 2001 From: Paul Rauser <paulr@Pauls-Air.fritz.box> Date: Tue, 3 Sep 2024 16:27:06 +0200 Subject: [PATCH] chore: create clean task branch --- src/shoes/.gitkeep | 0 src/shoes/App.java | 58 ------------------------------------- src/shoes/Boots.java | 7 ----- src/shoes/Box.java | 36 ----------------------- src/shoes/BoxException.java | 7 ----- src/shoes/Shelf.java | 55 ----------------------------------- src/shoes/ShoeBox.java | 11 ------- src/shoes/Shoes.java | 16 ---------- src/shoes/Sneakers.java | 7 ----- 9 files changed, 197 deletions(-) create mode 100644 src/shoes/.gitkeep delete mode 100644 src/shoes/App.java delete mode 100644 src/shoes/Boots.java delete mode 100644 src/shoes/Box.java delete mode 100644 src/shoes/BoxException.java delete mode 100644 src/shoes/Shelf.java delete mode 100644 src/shoes/ShoeBox.java delete mode 100644 src/shoes/Shoes.java delete mode 100644 src/shoes/Sneakers.java diff --git a/src/shoes/.gitkeep b/src/shoes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/shoes/App.java b/src/shoes/App.java deleted file mode 100644 index d87b89e..0000000 --- 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 152d834..0000000 --- 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 f54f67d..0000000 --- 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 2e03a28..0000000 --- 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 9b9a7f0..0000000 --- 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 a6d6a29..0000000 --- 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 5db623a..0000000 --- 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 81011f3..0000000 --- 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); - } -} -- GitLab