├── .devcontainer └── devcontainer.json ├── .gitignore ├── .idea ├── .gitignore ├── google-java-format.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── Adventure-Game ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a02adventure │ │ │ ├── Cell.java │ │ │ ├── CellImpl.java │ │ │ ├── Direction.java │ │ │ ├── Game.java │ │ │ ├── GameImpl.java │ │ │ ├── Inventory.java │ │ │ ├── InventoryImpl.java │ │ │ ├── Item.java │ │ │ ├── ItemImpl.java │ │ │ ├── Main.java │ │ │ ├── Map.java │ │ │ ├── MapImpl.java │ │ │ ├── MapUNC.java │ │ │ ├── Player.java │ │ │ ├── PlayerImpl.java │ │ │ ├── Position.java │ │ │ └── PositionImpl.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a02adventure │ │ ├── CellImplTest.java │ │ ├── GameImplTest.java │ │ ├── InventoryImplTest.java │ │ ├── ItemImplTest.java │ │ ├── MapImplTest.java │ │ ├── PlayerImplTest.java │ │ └── PositionImplTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a02adventure │ │ ├── Cell.class │ │ ├── CellImpl.class │ │ ├── Direction.class │ │ ├── Game.class │ │ ├── GameImpl.class │ │ ├── Inventory.class │ │ ├── InventoryImpl.class │ │ ├── Item.class │ │ ├── ItemImpl.class │ │ ├── Main.class │ │ ├── Map.class │ │ ├── MapImpl.class │ │ ├── MapUNC.class │ │ ├── Player.class │ │ ├── PlayerImpl.class │ │ ├── Position.class │ │ ├── PositionImpl$1.class │ │ └── PositionImpl.class │ └── test-classes │ └── com │ └── comp301 │ └── a02adventure │ ├── CellImplTest.class │ ├── GameImplTest.class │ ├── InventoryImplTest.class │ ├── ItemImplTest.class │ ├── MapImplTest.class │ ├── PlayerImplTest.class │ └── PositionImplTest.class ├── Algorithms-Notes └── algorithms.pdf ├── Decorators ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a06image │ │ │ ├── BorderDecorator.java │ │ │ ├── CircleDecorator.java │ │ │ ├── Image.java │ │ │ ├── ImageDisplay.java │ │ │ ├── Main.java │ │ │ ├── PictureImage.java │ │ │ ├── SolidColorImage.java │ │ │ ├── SquareDecorator.java │ │ │ └── ZoomDecorator.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a06image │ │ └── ImageDecoratorsTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a06image │ │ ├── BorderDecorator.class │ │ ├── CircleDecorator.class │ │ ├── Image.class │ │ ├── ImageDisplay.class │ │ ├── Main.class │ │ ├── PictureImage.class │ │ ├── SolidColorImage.class │ │ ├── SquareDecorator.class │ │ └── ZoomDecorator.class │ └── test-classes │ └── com │ └── comp301 │ └── a06image │ └── ImageDecoratorsTest.class ├── Design-Patterns-Info ├── Abstraction, Composition & Aggregation.pdf ├── Asynchronous Programming.pdf ├── Decorators.pdf ├── Encapsulation & OOP.pdf ├── Exceptions & Error Handling.pdf ├── Iterators & Iterable.pdf ├── JavaFX.pdf ├── Model-View-Controller.pdf ├── Observers.pdf ├── README.md ├── Singleton, Multiton, Factory & Strategy.pdf ├── Unit Testing & JUnit.pdf └── Web Development (Bonus).pdf ├── Design-Patterns.iml ├── DesignPatterns.md ├── Exceptions ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a03exceptions │ │ │ ├── Adept.java │ │ │ ├── Jedi.java │ │ │ ├── NegativeValueException.java │ │ │ ├── Novice.java │ │ │ └── Printer.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a03exceptions │ │ ├── AdeptTest.java │ │ ├── JediTest.java │ │ └── NoviceTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a03exceptions │ │ ├── Adept.class │ │ ├── Jedi.class │ │ ├── NegativeValueException.class │ │ ├── Novice.class │ │ └── Printer.class │ └── test-classes │ └── com │ └── comp301 │ └── a03exceptions │ ├── AdeptTest$1.class │ ├── AdeptTest$TestPrinter.class │ ├── AdeptTest.class │ ├── JediTest.class │ ├── NoviceTest$1.class │ ├── NoviceTest$TestPrinter.class │ └── NoviceTest.class ├── Inheritance ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a01sushi │ │ │ ├── Avocado.java │ │ │ ├── AvocadoPortion.java │ │ │ ├── Crab.java │ │ │ ├── CrabPortion.java │ │ │ ├── Eel.java │ │ │ ├── EelPortion.java │ │ │ ├── Ingredient.java │ │ │ ├── IngredientGeneral.java │ │ │ ├── IngredientPortion.java │ │ │ ├── IngredientPortionGeneral.java │ │ │ ├── Nigiri.java │ │ │ ├── Rice.java │ │ │ ├── RicePortion.java │ │ │ ├── Roll.java │ │ │ ├── Sashimi.java │ │ │ ├── Seaweed.java │ │ │ ├── SeaweedPortion.java │ │ │ ├── Shrimp.java │ │ │ ├── ShrimpPortion.java │ │ │ ├── Sushi.java │ │ │ ├── Tuna.java │ │ │ ├── TunaPortion.java │ │ │ ├── Yellowtail.java │ │ │ └── YellowtailPortion.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a01sushi │ │ ├── IngredientPortionTest.java │ │ ├── IngredientTest.java │ │ ├── NigiriTest.java │ │ ├── RollTest.java │ │ └── SashimiTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a01sushi │ │ ├── Avocado.class │ │ ├── AvocadoPortion.class │ │ ├── Crab.class │ │ ├── CrabPortion.class │ │ ├── Eel.class │ │ ├── EelPortion.class │ │ ├── Ingredient.class │ │ ├── IngredientGeneral.class │ │ ├── IngredientPortion.class │ │ ├── IngredientPortionGeneral.class │ │ ├── Nigiri$1.class │ │ ├── Nigiri$NigiriType.class │ │ ├── Nigiri.class │ │ ├── Rice.class │ │ ├── RicePortion.class │ │ ├── Roll.class │ │ ├── Sashimi$1.class │ │ ├── Sashimi$SashimiType.class │ │ ├── Sashimi.class │ │ ├── Seaweed.class │ │ ├── SeaweedPortion.class │ │ ├── Shrimp.class │ │ ├── ShrimpPortion.class │ │ ├── Sushi.class │ │ ├── Tuna.class │ │ ├── TunaPortion.class │ │ ├── Yellowtail.class │ │ └── YellowtailPortion.class │ └── test-classes │ └── com │ └── comp301 │ └── a01sushi │ ├── IngredientPortionTest.class │ ├── IngredientTest.class │ ├── NigiriTest.class │ ├── RollTest.class │ └── SashimiTest.class ├── Iterator ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a05driver │ │ │ ├── Driver.java │ │ │ ├── DriverImpl.java │ │ │ ├── ExpandingProximityIterator.java │ │ │ ├── Position.java │ │ │ ├── PositionImpl.java │ │ │ ├── ProximityIterator.java │ │ │ ├── SnakeOrderAcrossPoolsIterator.java │ │ │ ├── Vehicle.java │ │ │ └── VehicleImpl.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a05driver │ │ ├── ExpandingProximityIteratorTest.java │ │ ├── ProximityIteratorTest.java │ │ └── SnakeOrderAcrossPoolsIteratorTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a05driver │ │ ├── Driver.class │ │ ├── DriverImpl.class │ │ ├── ExpandingProximityIterator.class │ │ ├── Position.class │ │ ├── PositionImpl.class │ │ ├── ProximityIterator.class │ │ ├── SnakeOrderAcrossPoolsIterator.class │ │ ├── Vehicle.class │ │ └── VehicleImpl.class │ └── test-classes │ └── com │ └── comp301 │ └── a05driver │ ├── ExpandingProximityIteratorTest.class │ ├── ProximityIteratorTest.class │ └── SnakeOrderAcrossPoolsIteratorTest.class ├── LICENSE ├── Model-View-Controllers ├── Game-2048-JavaFX │ ├── LICENSE │ ├── README.md │ ├── img │ │ ├── instructions.png │ │ ├── ui.png │ │ └── welcome.png │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ ├── module-info.java │ │ │ │ └── org │ │ │ │ │ └── example │ │ │ │ │ └── game2048javafx │ │ │ │ │ ├── Controller.java │ │ │ │ │ ├── Game2048.java │ │ │ │ │ ├── Main.java │ │ │ │ │ ├── Model.java │ │ │ │ │ └── View.java │ │ │ └── resources │ │ │ │ ├── favicon.png │ │ │ │ └── org │ │ │ │ └── example │ │ │ │ └── game2048javafx │ │ │ │ ├── fonts │ │ │ │ ├── LICENSE.md │ │ │ │ ├── Poppins-Black.ttf │ │ │ │ ├── Poppins-BlackItalic.ttf │ │ │ │ ├── Poppins-Bold.ttf │ │ │ │ ├── Poppins-BoldItalic.ttf │ │ │ │ ├── Poppins-ExtraBold.ttf │ │ │ │ ├── Poppins-ExtraBoldItalic.ttf │ │ │ │ ├── Poppins-ExtraLight.ttf │ │ │ │ ├── Poppins-ExtraLightItalic.ttf │ │ │ │ ├── Poppins-Italic.ttf │ │ │ │ ├── Poppins-Light.ttf │ │ │ │ ├── Poppins-LightItalic.ttf │ │ │ │ ├── Poppins-Medium.ttf │ │ │ │ ├── Poppins-MediumItalic.ttf │ │ │ │ ├── Poppins-Regular.ttf │ │ │ │ ├── Poppins-SemiBold.ttf │ │ │ │ ├── Poppins-SemiBoldItalic.ttf │ │ │ │ ├── Poppins-Thin.ttf │ │ │ │ ├── Poppins-ThinItalic.ttf │ │ │ │ └── README.md │ │ │ │ ├── hello-view.fxml │ │ │ │ └── styles.css │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── example │ │ │ └── game2048javafx │ │ │ └── ModelTest.java │ └── target │ │ ├── classes │ │ ├── favicon.png │ │ ├── module-info.class │ │ └── org │ │ │ └── example │ │ │ └── game2048javafx │ │ │ ├── Controller.class │ │ │ ├── Game2048$1.class │ │ │ ├── Game2048.class │ │ │ ├── Main.class │ │ │ ├── Model.class │ │ │ ├── View.class │ │ │ ├── fonts │ │ │ ├── LICENSE.md │ │ │ ├── Poppins-Black.ttf │ │ │ ├── Poppins-BlackItalic.ttf │ │ │ ├── Poppins-Bold.ttf │ │ │ ├── Poppins-BoldItalic.ttf │ │ │ ├── Poppins-ExtraBold.ttf │ │ │ ├── Poppins-ExtraBoldItalic.ttf │ │ │ ├── Poppins-ExtraLight.ttf │ │ │ ├── Poppins-ExtraLightItalic.ttf │ │ │ ├── Poppins-Italic.ttf │ │ │ ├── Poppins-Light.ttf │ │ │ ├── Poppins-LightItalic.ttf │ │ │ ├── Poppins-Medium.ttf │ │ │ ├── Poppins-MediumItalic.ttf │ │ │ ├── Poppins-Regular.ttf │ │ │ ├── Poppins-SemiBold.ttf │ │ │ ├── Poppins-SemiBoldItalic.ttf │ │ │ ├── Poppins-Thin.ttf │ │ │ ├── Poppins-ThinItalic.ttf │ │ │ └── README.md │ │ │ ├── hello-view.fxml │ │ │ └── styles.css │ │ ├── maven-status │ │ └── maven-compiler-plugin │ │ │ └── compile │ │ │ └── default-compile │ │ │ ├── createdFiles.lst │ │ │ └── inputFiles.lst │ │ └── test-classes │ │ └── org │ │ └── example │ │ └── game2048javafx │ │ └── ModelTest.class └── README.md ├── Observers ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a08shopping │ │ │ ├── Customer.java │ │ │ ├── CustomerImpl.java │ │ │ ├── Main.java │ │ │ ├── Product.java │ │ │ ├── ProductImpl.java │ │ │ ├── ReceiptItem.java │ │ │ ├── ReceiptItemImpl.java │ │ │ ├── SaleSpawner.java │ │ │ ├── Store.java │ │ │ ├── StoreImpl.java │ │ │ ├── StoreObserver.java │ │ │ ├── events │ │ │ ├── BackInStockEvent.java │ │ │ ├── OutOfStockEvent.java │ │ │ ├── PurchaseEvent.java │ │ │ ├── SaleEndEvent.java │ │ │ ├── SaleStartEvent.java │ │ │ └── StoreEvent.java │ │ │ └── exceptions │ │ │ ├── OutOfStockException.java │ │ │ └── ProductNotFoundException.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a08shopping │ │ └── AppTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a08shopping │ │ ├── Customer.class │ │ ├── CustomerImpl.class │ │ ├── Main.class │ │ ├── Product.class │ │ ├── ProductImpl.class │ │ ├── ReceiptItem.class │ │ ├── ReceiptItemImpl.class │ │ ├── SaleSpawner.class │ │ ├── Store.class │ │ ├── StoreImpl.class │ │ ├── StoreObserver.class │ │ ├── events │ │ ├── BackInStockEvent.class │ │ ├── OutOfStockEvent.class │ │ ├── PurchaseEvent.class │ │ ├── SaleEndEvent.class │ │ ├── SaleStartEvent.class │ │ └── StoreEvent.class │ │ └── exceptions │ │ ├── OutOfStockException.class │ │ └── ProductNotFoundException.class │ └── test-classes │ └── com │ └── comp301 │ └── a08shopping │ └── AppTest.class ├── README.md ├── Singleton-Multiton-Factory ├── README.md ├── pom.xml ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── comp301 │ │ │ └── a07pizza │ │ │ ├── Cheese.java │ │ │ ├── Crust.java │ │ │ ├── Ingredient.java │ │ │ ├── IngredientImpl.java │ │ │ ├── Pizza.java │ │ │ ├── PizzaFactory.java │ │ │ ├── PizzaImpl.java │ │ │ ├── Sauce.java │ │ │ └── Topping.java │ └── test │ │ └── java │ │ └── com │ │ └── comp301 │ │ └── a07pizza │ │ └── PizzaFactoryTest.java └── target │ ├── classes │ └── com │ │ └── comp301 │ │ └── a07pizza │ │ ├── Cheese.class │ │ ├── Crust.class │ │ ├── Ingredient.class │ │ ├── IngredientImpl.class │ │ ├── Pizza$Size.class │ │ ├── Pizza.class │ │ ├── PizzaFactory.class │ │ ├── PizzaImpl$1.class │ │ ├── PizzaImpl.class │ │ ├── Sauce.class │ │ └── Topping.class │ └── test-classes │ └── com │ └── comp301 │ └── a07pizza │ └── PizzaFactoryTest.class └── img └── adventure.png /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Java Maven Dev Container", 3 | "image": "mcr.microsoft.com/devcontainers/java:1-17", 4 | "features": { 5 | "ghcr.io/devcontainers/features/maven:1": { 6 | "version": "latest" 7 | } 8 | }, 9 | "settings": { 10 | "terminal.integrated.defaultProfile.linux": "bash" 11 | }, 12 | "extensions": [ 13 | "vscjava.vscode-java-pack", 14 | "vscjava.vscode-maven", 15 | "redhat.vscode-yaml" 16 | ], 17 | "postCreateCommand": "mvn clean install", 18 | "remoteUser": "vscode", 19 | "mounts": [ 20 | "source=/home/vscode/.m2,target=/root/.m2,type=bind" 21 | ], 22 | "forwardPorts": [8080, 5005], 23 | "containerEnv": { 24 | "JAVA_HOME": "/usr/lib/jvm/java-17-openjdk" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/google-java-format.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Adventure-Game/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.comp301.a02adventure 8 | a02-adventure 9 | 1.0-SNAPSHOT 10 | 11 | a02-adventure 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.11 26 | test 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | maven-clean-plugin 36 | 3.1.0 37 | 38 | 39 | 40 | maven-resources-plugin 41 | 3.0.2 42 | 43 | 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 48 | maven-surefire-plugin 49 | 2.22.1 50 | 51 | 52 | maven-jar-plugin 53 | 3.0.2 54 | 55 | 56 | maven-install-plugin 57 | 2.5.2 58 | 59 | 60 | maven-deploy-plugin 61 | 2.8.2 62 | 63 | 64 | 65 | maven-site-plugin 66 | 3.7.1 67 | 68 | 69 | maven-project-info-reports-plugin 70 | 3.0.0 71 | 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-compiler-plugin 78 | 79 | 8 80 | 8 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Cell.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** 4 | * The Cell interface represents a cell in the game map. Each cell has a name, description, and 5 | * position. 6 | */ 7 | public interface Cell { 8 | // ******************************************************************************** 9 | // GETTER METHODS 10 | 11 | /** 12 | * Getter method for the cell's name 13 | * 14 | * @return the name of the cell 15 | */ 16 | String getName(); 17 | 18 | /** 19 | * Getter method for the cell's description 20 | * 21 | * @return the description of the cell 22 | */ 23 | String getDescription(); 24 | 25 | /** 26 | * Getter method for the position of the cell 27 | * 28 | * @return the position of the cell 29 | */ 30 | Position getPosition(); 31 | 32 | /** 33 | * Getter method for the "chest" Inventory object stored at the cell 34 | * 35 | * @return the chest of the cell 36 | */ 37 | Inventory getChest(); 38 | 39 | /** 40 | * Getter method which returns true if the cell has been visited 41 | * 42 | * @return true if the cell has been visited, false otherwise 43 | */ 44 | boolean getIsVisited(); 45 | 46 | /** 47 | * Returns true if the cell has a chest 48 | * 49 | * @return true if the cell has a chest, false otherwise 50 | */ 51 | boolean hasChest(); 52 | 53 | // ******************************************************************************** 54 | // SETTER METHODS 55 | 56 | // Note: The setName(), setDescription(), and setChest() methods should perform setter validation 57 | // and throw an IllegalArgumentException for incoming "null" values 58 | 59 | /** 60 | * Setter method for changing the cell's name 61 | * 62 | * @param name the name of the cell 63 | */ 64 | void setName(String name); 65 | 66 | /** 67 | * Setter method for changing the cell's description 68 | * 69 | * @param description the description of the cell 70 | */ 71 | void setDescription(String description); 72 | 73 | /** 74 | * Setter method for the "chest" Inventory object stored at the cell 75 | * 76 | * @param chest the chest of the cell 77 | */ 78 | void setChest(Inventory chest); 79 | 80 | /** Marks that the cell has been visited */ 81 | void visit(); 82 | } 83 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Direction.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** The {@code Direction} enum represents the four cardinal directions. */ 4 | public enum Direction { 5 | 6 | /** Represents the north direction. */ 7 | NORTH, 8 | 9 | /** Represents the south direction. */ 10 | SOUTH, 11 | 12 | /** Represents the east direction. */ 13 | EAST, 14 | 15 | /** Represents the west direction. */ 16 | WEST 17 | } 18 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Inventory.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * An Inventory object represents a collection of items. An Inventory object can be used to store 7 | * items and transfer items between inventories. 8 | */ 9 | public interface Inventory { 10 | /** 11 | * Returns true if the Inventory is empty 12 | * 13 | * @return true if the Inventory is empty, false otherwise 14 | */ 15 | boolean isEmpty(); 16 | 17 | /** 18 | * Getter method for the number of Items currently stored in the inventory 19 | * 20 | * @return the number of Items currently stored in the inventory 21 | */ 22 | int getNumItems(); 23 | 24 | /** 25 | * Getter method which returns a cloned list of the Items in the Inventory 26 | * 27 | * @return a cloned list of the Items in the Inventory 28 | */ 29 | List getItems(); 30 | 31 | /** 32 | * Adds an Item to the Inventory 33 | * 34 | * @param item the Item to be added to the Inventory 35 | */ 36 | void addItem(Item item); 37 | 38 | /** 39 | * Removes an Item from the Inventory 40 | * 41 | * @param item the Item to be removed from the Inventory 42 | */ 43 | void removeItem(Item item); 44 | 45 | /** Clears the Inventory */ 46 | void clear(); 47 | 48 | /** 49 | * Removes the Items from an "other" Inventory, and adds them into "this" Inventory 50 | * 51 | * @param other the Inventory to transfer Items from 52 | */ 53 | void transferFrom(Inventory other); 54 | } 55 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Item.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** 4 | * The Item interface represents an item that can be picked up and stored in a player's inventory. 5 | */ 6 | public interface Item { 7 | /** 8 | * Getter method to retrieve the name of the Item 9 | * 10 | * @return the name of the Item 11 | */ 12 | String getName(); 13 | 14 | /** 15 | * Every class in Java is a descendant of a built-in superclass, called "Object". The Object 16 | * superclass defines a few useful methods for every Java object, like equals() and toString(). 17 | * Since Object is the superclass to every class, that means every Java object has these methods. 18 | * Programmers can override them, if necessary, to supply a subclass-specific version of the 19 | * method. Every Item class should override both equals() and toString(). 20 | * 21 | *

The equals() method tests to see if the "this" object is the same as the "other" object, 22 | * returning true if they are the same, or false if they are not. For this method, assume two 23 | * Items are the same if they have the same "name" String. 24 | * 25 | * @param other the other item to compare 26 | * @return true if the item is equal to the other item, false otherwise 27 | */ 28 | @Override 29 | boolean equals(Object other); 30 | 31 | /** 32 | * Every class in Java is a descendant of a built-in superclass, called "Object". The Object 33 | * superclass defines a few useful methods for every Java object, like equals() and toString(). 34 | * Since Object is the superclass to every class, that means every Java object has these methods. 35 | * Programmers can override them, if necessary, to supply a subclass-specific version of the 36 | * method. Every Item class should override both equals() and toString(). 37 | * 38 | *

The toString() method generates a human-readable, String representation of the object, 39 | * suitable for printing to the console either for debugging or for the eventual user to read. For 40 | * this method, assume the "string representation" of an Item is simply the item's name String. 41 | * 42 | * @return a string representation of the Item object 43 | */ 44 | @Override 45 | String toString(); 46 | } 47 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/ItemImpl.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** 4 | * An Item object represents an item that can be collected by a player in the game. An Item object 5 | * has a name that can be used to identify the item. 6 | */ 7 | public class ItemImpl implements Item { 8 | 9 | // Field to store the name of the item 10 | private final String name; 11 | 12 | /** 13 | * Constructs a new Item object with the specified name. 14 | * 15 | * @param name the name of the item 16 | */ 17 | public ItemImpl(String name) { 18 | if (name == null) { 19 | throw new IllegalArgumentException("Item's name cannot be null"); 20 | } 21 | 22 | this.name = name; 23 | } 24 | 25 | /** 26 | * A method that returns the name of the item. 27 | * 28 | * @return the name of the item 29 | */ 30 | @Override 31 | public String getName() { 32 | return this.name; 33 | } 34 | 35 | /** 36 | * A method that returns a string representation of the Item object. 37 | * 38 | * @return a string representation of the Item object 39 | */ 40 | @Override 41 | public String toString() { 42 | return this.name; 43 | } 44 | 45 | /** 46 | * A method that returns true if the item is equal to another item, false otherwise. Two items are 47 | * considered equal if their names are equal. 48 | * 49 | * @param other the other item to compare 50 | * @return true if the item is equal to the other item, false otherwise 51 | */ 52 | @Override 53 | public boolean equals(Object other) { 54 | boolean isEqual = false; 55 | 56 | // Check if the other object is null - if so, they are not equal 57 | if (other == null) { 58 | return false; 59 | } 60 | 61 | // Check if the other object is exactly the same object as the current one - if so, they are 62 | // equal 63 | if (this == other) { 64 | return true; 65 | } 66 | 67 | // Check if the other object is an instance of Item - if so, compare the names 68 | if (other instanceof Item) { 69 | Item otherItem = (Item) other; 70 | // If the names are equal, the items are equal 71 | isEqual = this.name.equals(otherItem.getName()); 72 | return isEqual; 73 | } 74 | 75 | return isEqual; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Map.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** The Map interface represents a 2D grid of cells. The map is defined by its width and height */ 4 | public interface Map { 5 | /** 6 | * Getter method for the width of the map 7 | * 8 | * @return the width of the map 9 | */ 10 | int getWidth(); 11 | 12 | /** 13 | * Getter method for the height of the map 14 | * 15 | * @return the height of the map 16 | */ 17 | int getHeight(); 18 | 19 | /** 20 | * Getter method for a specific cell on the map. Throws an IndexOutOfBoundsException for 21 | * coordinate parameters that are not on the map 22 | * 23 | * @param x the x-coordinate of the cell 24 | * @param y the y-coordinate of the cell 25 | * @return the cell at the specified coordinates 26 | */ 27 | Cell getCell(int x, int y); 28 | 29 | /** 30 | * Overloaded getter method for a specific cell on the map. Throws an IndexOutOfBoundsException 31 | * for coordinate parameters that are not on the map 32 | * 33 | * @param position the position of the cell 34 | * @return the cell at the specified position 35 | */ 36 | Cell getCell(Position position); 37 | 38 | /** 39 | * Initializes a new CellImpl object at the specified location on the map, overwriting any 40 | * existing Cell at that location. Throws an IndexOutOfBoundsException for coordinate parameters 41 | * that are not on the map 42 | * 43 | * @param x the x-coordinate of the cell 44 | * @param y the y-coordinate of the cell 45 | */ 46 | void initCell(int x, int y); 47 | 48 | /** 49 | * Getter method for the total number of items that need to be collected in order for the player 50 | * to win. This field is immutable. 51 | * 52 | * @return the total number of items that need to be collected 53 | */ 54 | int getNumItems(); 55 | } 56 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Player.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** 4 | * The Player interface represents a player in the game. The player has a position, an inventory, 5 | * and a name. 6 | */ 7 | public interface Player { 8 | /** 9 | * Getter method for the player's current position 10 | * 11 | * @return the player's current position 12 | */ 13 | Position getPosition(); 14 | 15 | /** 16 | * Getter method for the player's inventory 17 | * 18 | * @return the player's inventory 19 | */ 20 | Inventory getInventory(); 21 | 22 | /** 23 | * Getter method for the player's name 24 | * 25 | * @return the player's name 26 | */ 27 | String getName(); 28 | 29 | /** 30 | * Blindly moves the player's position one unit in the indicated direction, without checking 31 | * whether the new location is valid 32 | * 33 | * @param direction the direction in which to move the player 34 | */ 35 | void move(Direction direction); 36 | } 37 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/PlayerImpl.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** The PlayerImpl class implements the Player interface and represents a player in the game. */ 4 | public class PlayerImpl implements Player { 5 | 6 | // Field to store the player's name 7 | private String name; 8 | // Field to store the player's inventory 9 | private Inventory inventory; 10 | // Field to store the player's position 11 | private Position position; 12 | 13 | /** 14 | * Constructs a new Player object with the specified name and starting position. 15 | * 16 | * @param name the name of the player 17 | * @param startX the x-coordinate of the player's starting position 18 | * @param startY the y-coordinate of the player's starting position 19 | */ 20 | public PlayerImpl(String name, int startX, int startY) { 21 | if (name == null) { 22 | throw new IllegalArgumentException("Name string cannot be null"); 23 | } 24 | 25 | // Initialize the player's name, inventory, and position 26 | this.name = name; 27 | this.inventory = new InventoryImpl(); 28 | this.position = new PositionImpl(startX, startY); 29 | } 30 | 31 | /** 32 | * A method that returns the name of the player. 33 | * 34 | * @return the name of the player 35 | */ 36 | @Override 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | /** 42 | * A method that returns the player's inventory. 43 | * 44 | * @return the player's inventory 45 | */ 46 | @Override 47 | public Inventory getInventory() { 48 | return this.inventory; 49 | } 50 | 51 | /** 52 | * A method that returns the player's current position. 53 | * 54 | * @return the player's current position 55 | */ 56 | @Override 57 | public Position getPosition() { 58 | return this.position; 59 | } 60 | 61 | /** 62 | * A method that moves the player in the specified direction. 63 | * 64 | * @param direction the direction in which to move the player 65 | */ 66 | @Override 67 | public void move(Direction direction) { 68 | if (direction == null) { 69 | throw new IllegalArgumentException("Direction cannot be null"); 70 | } 71 | 72 | // Get the new position by moving in the given direction 73 | Position newPosition = this.position.getNeighbor(direction); 74 | 75 | // Move the player to the new position 76 | this.position = newPosition; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Adventure-Game/src/main/java/com/comp301/a02adventure/Position.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | /** 4 | * The Position interface represents a position on a 2D grid. The position is defined by its x and y 5 | * coordinates. The Position interface provides methods to get the x and y coordinates of the 6 | * position and to get a neighbor position in a specified direction. 7 | */ 8 | public interface Position { 9 | /** 10 | * Getter method for the x-coordinate of the position 11 | * 12 | * @return the x-coordinate of the position 13 | */ 14 | int getX(); 15 | 16 | /** 17 | * Getter method for the y-coordinate of the position 18 | * 19 | * @return the y-coordinate of the position 20 | */ 21 | int getY(); 22 | 23 | /** 24 | * Constructs and returns a new Position object located one unit in the indicted direction from 25 | * the "this" object 26 | * 27 | * @param direction the direction in which to find the neighbor 28 | * @return a new Position object located one unit in the indicted direction from the "this" object 29 | */ 30 | Position getNeighbor(Direction direction); 31 | } 32 | -------------------------------------------------------------------------------- /Adventure-Game/src/test/java/com/comp301/a02adventure/ItemImplTest.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | /** 7 | * This class contains a set of test cases that can be used to test the implementation of the Item 8 | * interface - the ItemImpl class. 9 | */ 10 | public class ItemImplTest { 11 | 12 | /** 13 | * Default constructor for the ItemImplTest class. 14 | * This constructor is intentionally left empty since no specific initialization is needed for the tests. 15 | */ 16 | public ItemImplTest() { 17 | // No initialization required for this test class. 18 | } 19 | 20 | /** This test case tests the constructor and getName method of the Item interface. */ 21 | @Test 22 | public void testItemConstructorAndGetName() { 23 | Item item = new ItemImpl("Sword"); 24 | assertEquals("Sword", item.getName()); 25 | } 26 | 27 | /** This test case tests the constructor of the Item interface with a null name. */ 28 | @Test(expected = IllegalArgumentException.class) 29 | public void testItemConstructorNullName() { 30 | new ItemImpl(null); 31 | } 32 | 33 | /** This test case tests the equals method of the Item interface. */ 34 | @Test 35 | public void testItemEquals() { 36 | Item item1 = new ItemImpl("Shield"); 37 | Item item2 = new ItemImpl("Shield"); 38 | Item item3 = new ItemImpl("Potion"); 39 | 40 | // Case 1: Two items with the same name are the same 41 | assertTrue(item1.equals(item2)); 42 | // Case 2: Two items with different names are not the same 43 | assertFalse(item1.equals(item3)); 44 | // Case 3: An item is not the same as null or a non-item object 45 | assertFalse(item1.equals(null)); 46 | // Case 4: An item is not the same as an object with a different type 47 | assertFalse(item1.equals("Not an item")); 48 | } 49 | 50 | /** This test case tests the toString method of the Item interface. */ 51 | @Test 52 | public void testItemToString() { 53 | Item item = new ItemImpl("Bow"); 54 | assertEquals("Bow", item.toString()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Adventure-Game/src/test/java/com/comp301/a02adventure/PositionImplTest.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a02adventure; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.*; 5 | 6 | /** 7 | * This class contains a set of test cases that can be used to test the implementation of the 8 | * Position interface - the PositionImpl class. 9 | */ 10 | public class PositionImplTest { 11 | 12 | /** 13 | * Default constructor for the PositionImplTest class. 14 | * This constructor is intentionally left empty since no specific initialization is needed for the tests. 15 | */ 16 | public PositionImplTest() { 17 | // No initialization required for this test class. 18 | } 19 | 20 | /** This test case tests the constructor and getter methods of the Position interface. */ 21 | @Test 22 | public void testPositionConstructorAndGetters() { 23 | Position position = new PositionImpl(2, 3); 24 | assertEquals(2, position.getX()); 25 | assertEquals(3, position.getY()); 26 | } 27 | 28 | /** This test case tests the equals method of the Position interface. */ 29 | @Test 30 | public void testPositionEquals() { 31 | Position position1 = new PositionImpl(1, 2); 32 | Position position2 = new PositionImpl(1, 2); 33 | Position position3 = new PositionImpl(2, 1); 34 | 35 | // Case 1: Two positions with the same x and y coordinates are the same 36 | assertTrue(position1.equals(position2)); 37 | // Case 2: Two positions with different x and y coordinates are not the same 38 | assertFalse(position1.equals(position3)); 39 | // Case 3: A position is not the same as null or a non-position object 40 | assertFalse(position1.equals(null)); 41 | // Case 4: A position is not the same as an object with a different type 42 | assertFalse(position1.equals("Not a position")); 43 | } 44 | 45 | /** This test case tests the toString method of the Position interface. */ 46 | @Test 47 | public void testPositionToString() { 48 | Position position = new PositionImpl(4, 5); 49 | assertEquals("(4, 5)", position.toString()); 50 | } 51 | 52 | /** This test case tests the getNeighbor method of the Position interface. */ 53 | @Test 54 | public void testGetNeighbor() { 55 | Position position = new PositionImpl(3, 3); 56 | 57 | Position northNeighbor = position.getNeighbor(Direction.NORTH); 58 | assertEquals(new PositionImpl(3, 4), northNeighbor); 59 | 60 | Position southNeighbor = position.getNeighbor(Direction.SOUTH); 61 | assertEquals(new PositionImpl(3, 2), southNeighbor); 62 | 63 | Position eastNeighbor = position.getNeighbor(Direction.EAST); 64 | assertEquals(new PositionImpl(4, 3), eastNeighbor); 65 | 66 | Position westNeighbor = position.getNeighbor(Direction.WEST); 67 | assertEquals(new PositionImpl(2, 3), westNeighbor); 68 | } 69 | 70 | /** 71 | * This test case tests the getNeighbor method of the Position interface with an invalid 72 | * direction. 73 | */ 74 | @Test(expected = IllegalArgumentException.class) 75 | public void testInvalidDirection() { 76 | Position position = new PositionImpl(0, 0); 77 | position.getNeighbor(null); // Should throw an IllegalArgumentException 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Cell.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Cell.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/CellImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/CellImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Direction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Direction.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Game.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Game.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/GameImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/GameImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Inventory.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Inventory.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/InventoryImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/InventoryImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Item.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/ItemImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/ItemImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Main.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Map.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Map.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/MapImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/MapImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/MapUNC.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/MapUNC.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Player.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Player.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/PlayerImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/PlayerImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/Position.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/Position.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/PositionImpl$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/PositionImpl$1.class -------------------------------------------------------------------------------- /Adventure-Game/target/classes/com/comp301/a02adventure/PositionImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/classes/com/comp301/a02adventure/PositionImpl.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/CellImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/CellImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/GameImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/GameImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/InventoryImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/InventoryImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/ItemImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/ItemImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/MapImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/MapImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/PlayerImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/PlayerImplTest.class -------------------------------------------------------------------------------- /Adventure-Game/target/test-classes/com/comp301/a02adventure/PositionImplTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Adventure-Game/target/test-classes/com/comp301/a02adventure/PositionImplTest.class -------------------------------------------------------------------------------- /Algorithms-Notes/algorithms.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Algorithms-Notes/algorithms.pdf -------------------------------------------------------------------------------- /Decorators/src/main/java/com/comp301/a06image/Image.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a06image; 2 | 3 | import java.awt.Color; 4 | 5 | /** 6 | * The Image interface represents an image with a width, height, and color. The color of a pixel can 7 | * be retrieved by calling the getPixelColor method. 8 | */ 9 | public interface Image { 10 | /** 11 | * Getter method to retrieve the color of a particular pixel in the image. Parameters x and y must 12 | * be non-negative, and must be less than the width and height of the image, respectively. 13 | * 14 | * @param x The x coordinate of the pixel 15 | * @param y The y coordinate of the pixel 16 | * @return The color of the pixel located at position (x, y) 17 | */ 18 | Color getPixelColor(int x, int y); 19 | 20 | /** 21 | * Getter method for the number of pixels in the horizontal direction of the image 22 | * 23 | * @return The width of the image 24 | */ 25 | int getWidth(); 26 | 27 | /** 28 | * Getter method for the number of pixels in the vertical direction of the image 29 | * 30 | * @return The height of the image 31 | */ 32 | int getHeight(); 33 | 34 | /** 35 | * Getter method for the number of layers in the image 36 | * 37 | * @return The number of layers in the image 38 | */ 39 | int getNumLayers(); 40 | } 41 | -------------------------------------------------------------------------------- /Decorators/src/main/java/com/comp301/a06image/ImageDisplay.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a06image; 2 | 3 | import java.io.IOException; 4 | import javafx.application.Application; 5 | import javafx.scene.Group; 6 | import javafx.scene.Scene; 7 | import javafx.scene.image.ImageView; 8 | import javafx.scene.image.PixelWriter; 9 | import javafx.scene.image.WritableImage; 10 | import javafx.stage.Stage; 11 | 12 | /** 13 | * This class contains code to display the decorated image on the screen when the Main class is 14 | * executed. You don't need to make any changes to this class for the assignment. 15 | */ 16 | public class ImageDisplay extends Application { 17 | 18 | /** Default constructor for the ImageDisplay class. */ 19 | public ImageDisplay() { 20 | // Default constructor 21 | } 22 | 23 | /** 24 | * The start method is called when the application is launched. It creates an image view and 25 | * displays the image on the screen. 26 | * 27 | * @param stage The primary stage for the application 28 | * @throws IOException If the image file cannot be loaded 29 | */ 30 | @Override 31 | public void start(Stage stage) throws IOException { 32 | // Create the image to display 33 | WritableImage fxImage = render(Main.makeImage()); 34 | 35 | // Set the image view 36 | ImageView imageView = new ImageView(fxImage); 37 | 38 | // Set the position of the image 39 | imageView.setX(0); 40 | imageView.setY(0); 41 | 42 | // Set the fit height and width of the image view 43 | imageView.setFitHeight(fxImage.getHeight()); 44 | imageView.setFitWidth(fxImage.getWidth()); 45 | 46 | // Set the preserve ratio of the image view 47 | imageView.setPreserveRatio(true); 48 | 49 | // Create a Group object 50 | Group root = new Group(imageView); 51 | 52 | // Create a scene object 53 | Scene scene = new Scene(root, fxImage.getWidth(), fxImage.getHeight()); 54 | 55 | // Set title to the Stage 56 | stage.setTitle("Image display"); 57 | 58 | // Add scene to the stage 59 | stage.setScene(scene); 60 | 61 | // Display the contents of the stage 62 | stage.show(); 63 | } 64 | 65 | /** 66 | * The render method converts an Image object to a WritableImage object that can be displayed on 67 | * the screen. 68 | * 69 | * @param img The Image object to be converted 70 | * @return The WritableImage object that can be displayed on the screen 71 | */ 72 | private WritableImage render(Image img) { 73 | WritableImage wi = new WritableImage(img.getWidth(), img.getHeight()); 74 | PixelWriter pw = wi.getPixelWriter(); 75 | for (int y = 0; y < img.getHeight(); y++) { 76 | for (int x = 0; x < img.getWidth(); x++) { 77 | pw.setArgb(x, y, (0xff << 24) | img.getPixelColor(x, y).getRGB()); 78 | } 79 | } 80 | return wi; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Decorators/src/main/java/com/comp301/a06image/Main.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a06image; 2 | 3 | import java.awt.Color; 4 | import java.io.IOException; 5 | import javafx.application.Application; 6 | 7 | /** 8 | * This class is the entry point for the image decorator application. You can use this class to test 9 | * your image decorator implementations. The makeImage() method below creates an image object and 10 | * applies a series of decorators to it. You can modify this method to test different decorators. 11 | * When you run the main() method below, the image you create will be displayed on the screen. 12 | */ 13 | public class Main { 14 | /** 15 | * Creates and returns an image object for testing. The image that this method produces will be 16 | * automatically displayed on the screen when main() is run below. Use this method to test 17 | * different decorators. 18 | * 19 | * @return The image object to be displayed 20 | * @throws IOException If the image file cannot be loaded 21 | */ 22 | public static Image makeImage() throws IOException { 23 | // Load the base image 24 | Image baseImage = new PictureImage("img/headshot.jpg"); 25 | 26 | // Apply a red border 27 | Image redBorderImage = new BorderDecorator(baseImage, 5, new Color(255, 0, 0)); 28 | 29 | // Apply a blue border 30 | Image blueBorderImage = new BorderDecorator(redBorderImage, 50, new Color(0, 0, 255)); 31 | 32 | // Apply a yellow circle 33 | Image yellowCircleImage = 34 | new CircleDecorator(blueBorderImage, 50, 50, 40, new Color(255, 255, 0)); 35 | 36 | // Apply an orange square 37 | Image orangeSquareImage = 38 | new SquareDecorator(yellowCircleImage, 100, 100, 40, new Color(200, 80, 10)); 39 | 40 | // Finally, apply a ZoomDecorator with a multiplier of 2 41 | Image finalImage = new ZoomDecorator(orangeSquareImage, 2); 42 | 43 | // Return the final image 44 | return finalImage; 45 | } 46 | 47 | /** 48 | * Use this method for testing your code. When main() runs, the image you created and decorated in 49 | * the makeImage() method above will be generated and displayed on the screen. You don't need to 50 | * make any changes to this main() method. 51 | * 52 | * @param args Command-line arguments 53 | */ 54 | public static void main(String[] args) { 55 | Application.launch(ImageDisplay.class, args); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Decorators/src/main/java/com/comp301/a06image/PictureImage.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a06image; 2 | 3 | import javax.imageio.ImageIO; 4 | import java.awt.Color; 5 | import java.awt.image.BufferedImage; 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * The PictureImage class is an Image implementation that represents an image loaded from a file on 11 | * disk. The image is represented as a BufferedImage object, and the color of a pixel can be 12 | * retrieved by calling the getPixelColor method. 13 | */ 14 | public class PictureImage implements Image { 15 | // Instance variable 16 | private BufferedImage image; 17 | 18 | /** 19 | * Constructor for the PictureImage class. Initializes the PictureImage with the image loaded from 20 | * the file at the specified pathname. 21 | * 22 | * @param pathname The pathname of the image file 23 | * @throws IOException If the image file cannot be loaded 24 | */ 25 | public PictureImage(String pathname) throws IOException { 26 | // Check for invalid arguments (null pathname) 27 | if (pathname == null) { 28 | throw new IllegalArgumentException("Pathname cannot be null."); 29 | } 30 | 31 | // Load the image from the file at the specified pathname 32 | // Initialize the PictureImage 33 | File file = new File(pathname); 34 | this.image = ImageIO.read(file); 35 | } 36 | 37 | /** 38 | * Returns the color of the pixel at the specified coordinates. 39 | * 40 | * @param x The x coordinate of the pixel 41 | * @param y The y coordinate of the pixel 42 | * @return The color of the pixel at the specified coordinates 43 | */ 44 | @Override 45 | public Color getPixelColor(int x, int y) { 46 | // Check for invalid arguments (negative x or y, or out-of-bounds x or y) 47 | if (x < 0) { 48 | throw new IllegalArgumentException("Pixel x-coordinate must be non-negative."); 49 | } 50 | 51 | if (y < 0) { 52 | throw new IllegalArgumentException("Pixel y-coordinate must be non-negative."); 53 | } 54 | 55 | if (x >= this.getWidth()) { 56 | throw new IllegalArgumentException("Pixel x-coordinate must be less than the image width."); 57 | } 58 | 59 | if (y >= this.getHeight()) { 60 | throw new IllegalArgumentException("Pixel y-coordinate must be less than the image height."); 61 | } 62 | 63 | // Retrieve the color of the pixel at position (x, y) 64 | int rgb = this.image.getRGB(x, y); 65 | return new Color(rgb, true); 66 | } 67 | 68 | /** 69 | * Returns the width of the image. 70 | * 71 | * @return The width of the image 72 | */ 73 | @Override 74 | public int getWidth() { 75 | return this.image.getWidth(); 76 | } 77 | 78 | /** 79 | * Returns the height of the image. 80 | * 81 | * @return The height of the image 82 | */ 83 | @Override 84 | public int getHeight() { 85 | return this.image.getHeight(); 86 | } 87 | 88 | /** 89 | * Returns the number of layers in the image. A PictureImage is a base image that has no layers, 90 | * so the number of layers is 1. 91 | * 92 | * @return The number of layers in the image 93 | */ 94 | @Override 95 | public int getNumLayers() { 96 | // A PictureImage is a base image that has no layers, so return 1 97 | return 1; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Decorators/src/main/java/com/comp301/a06image/SolidColorImage.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a06image; 2 | 3 | import java.awt.Color; 4 | 5 | /** 6 | * The SolidColorImage class is an Image implementation that represents an image with a solid color. 7 | * The image is defined by a width, a height, and a color. The color of a pixel can be retrieved by 8 | * calling the getPixelColor method. 9 | */ 10 | public class SolidColorImage implements Image { 11 | private int width; 12 | private int height; 13 | private Color color; 14 | 15 | /** 16 | * Constructor for the SolidColorImage class. Initializes the SolidColorImage with the specified 17 | * width, height, and color. 18 | * 19 | * @param width The width of the image 20 | * @param height The height of the image 21 | * @param color The color of the image 22 | * @throws IllegalArgumentException If the width or height is negative 23 | */ 24 | public SolidColorImage(int width, int height, Color color) { 25 | // Check for invalid arguments (negative width or height) 26 | if (width < 0 || height < 0) { 27 | throw new IllegalArgumentException("Width and height must be positive values."); 28 | } 29 | 30 | // Initialize the SolidColorImage 31 | this.width = width; 32 | this.height = height; 33 | this.color = color; 34 | } 35 | 36 | /** 37 | * Returns the color of the pixel at the specified coordinates. 38 | * 39 | * @param x The x coordinate of the pixel 40 | * @param y The y coordinate of the pixel 41 | * @return The color of the pixel at the specified coordinates 42 | */ 43 | @Override 44 | public Color getPixelColor(int x, int y) { 45 | // Check for invalid arguments (negative x or y, or out-of-bounds x or y) 46 | if (x < 0) { 47 | throw new IllegalArgumentException("Pixel x-coordinate must be non-negative."); 48 | } 49 | 50 | if (y < 0) { 51 | throw new IllegalArgumentException("Pixel y-coordinate must be non-negative."); 52 | } 53 | 54 | if (x >= this.width) { 55 | throw new IllegalArgumentException("Pixel x-coordinate must be less than the image width."); 56 | } 57 | 58 | if (y >= this.height) { 59 | throw new IllegalArgumentException("Pixel y-coordinate must be less than the image height."); 60 | } 61 | 62 | // Return the solid color of the image 63 | return this.color; 64 | } 65 | 66 | /** 67 | * Returns the width of the image. 68 | * 69 | * @return The width of the image 70 | */ 71 | @Override 72 | public int getWidth() { 73 | return this.width; 74 | } 75 | 76 | /** 77 | * Returns the height of the image. 78 | * 79 | * @return The height of the image 80 | */ 81 | @Override 82 | public int getHeight() { 83 | return this.height; 84 | } 85 | 86 | /** 87 | * Returns the number of layers in the image. A SolidColorImage is a base image that has no 88 | * layers, so the number of layers is 1. 89 | * 90 | * @return The number of layers in the image 91 | */ 92 | @Override 93 | public int getNumLayers() { 94 | // A SolidColorImage is a base image that has no layers, so return 1 95 | return 1; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/BorderDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/BorderDecorator.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/CircleDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/CircleDecorator.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/Image.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/Image.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/ImageDisplay.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/ImageDisplay.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/Main.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/PictureImage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/PictureImage.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/SolidColorImage.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/SolidColorImage.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/SquareDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/SquareDecorator.class -------------------------------------------------------------------------------- /Decorators/target/classes/com/comp301/a06image/ZoomDecorator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/classes/com/comp301/a06image/ZoomDecorator.class -------------------------------------------------------------------------------- /Decorators/target/test-classes/com/comp301/a06image/ImageDecoratorsTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Decorators/target/test-classes/com/comp301/a06image/ImageDecoratorsTest.class -------------------------------------------------------------------------------- /Design-Patterns-Info/Abstraction, Composition & Aggregation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Abstraction, Composition & Aggregation.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Asynchronous Programming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Asynchronous Programming.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Decorators.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Decorators.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Encapsulation & OOP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Encapsulation & OOP.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Exceptions & Error Handling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Exceptions & Error Handling.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Iterators & Iterable.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Iterators & Iterable.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/JavaFX.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/JavaFX.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Model-View-Controller.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Model-View-Controller.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Observers.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Observers.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Singleton, Multiton, Factory & Strategy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Singleton, Multiton, Factory & Strategy.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Unit Testing & JUnit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Unit Testing & JUnit.pdf -------------------------------------------------------------------------------- /Design-Patterns-Info/Web Development (Bonus).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Design-Patterns-Info/Web Development (Bonus).pdf -------------------------------------------------------------------------------- /Design-Patterns.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Exceptions/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.comp301.a03exceptions 8 | a03-exceptions 9 | 1.0-SNAPSHOT 10 | 11 | a03-exceptions 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.11 26 | test 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | maven-clean-plugin 36 | 3.1.0 37 | 38 | 39 | 40 | maven-resources-plugin 41 | 3.0.2 42 | 43 | 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 48 | maven-surefire-plugin 49 | 2.22.1 50 | 51 | 52 | maven-jar-plugin 53 | 3.0.2 54 | 55 | 56 | maven-install-plugin 57 | 2.5.2 58 | 59 | 60 | maven-deploy-plugin 61 | 2.8.2 62 | 63 | 64 | 65 | maven-site-plugin 66 | 3.7.1 67 | 68 | 69 | maven-project-info-reports-plugin 70 | 3.0.0 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Exceptions/src/main/java/com/comp301/a03exceptions/NegativeValueException.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a03exceptions; 2 | 3 | /** This exception indicates that a negative value was encountered. */ 4 | public class NegativeValueException extends RuntimeException { 5 | 6 | /** Constructor with a default message */ 7 | public NegativeValueException() { 8 | super("A negative value was encountered"); 9 | } 10 | 11 | /** 12 | * Constructor with a custom message 13 | * 14 | * @param message The message to display 15 | */ 16 | public NegativeValueException(String message) { 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Exceptions/src/main/java/com/comp301/a03exceptions/Printer.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a03exceptions; 2 | 3 | /** 4 | * You do not need to implement this interface for the assignment. This interface is used by the 5 | * autograder to interact with your code. Some of the problems in this assignment will ask you to 6 | * "print" information at specific parts in your code. Use the print() method below to accomplish 7 | * this. 8 | */ 9 | public interface Printer { 10 | 11 | /** 12 | * Call this method to "print" a String. Unlike System.out.println, this method doesn't actually 13 | * print the string to the console. Instead, it just sends the string value straight to the 14 | * autograder. 15 | */ 16 | void print(String value); 17 | } 18 | -------------------------------------------------------------------------------- /Exceptions/src/test/java/com/comp301/a03exceptions/JediTest.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a03exceptions; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | 6 | import org.junit.Test; 7 | 8 | /** Unit test for the Jedi class. */ 9 | public class JediTest { 10 | 11 | /** Test for section7 method */ 12 | @Test 13 | public void testSection7() { 14 | // Test case when n is negative, expecting a NegativeValueException 15 | try { 16 | Jedi.section7(-5); 17 | fail("Expected NegativeValueException was not thrown"); 18 | } catch (NegativeValueException e) { 19 | // Expected outcome, test passes 20 | } 21 | 22 | // Test case when n is non-negative, expecting no exception 23 | try { 24 | Jedi.section7(5); 25 | // If we reach here, it means no exception was thrown, which is expected 26 | } catch (NegativeValueException e) { 27 | fail("NegativeValueException should not be thrown for non-negative n"); 28 | } 29 | } 30 | 31 | /** Test for section8 method */ 32 | @Test 33 | public void testSection8() { 34 | // Test case when n is negative, should return "A NegativeValueException occurred" 35 | assertEquals("A NegativeValueException occurred", Jedi.section8(-1)); 36 | 37 | // Test case when n = 3 (which should throw IllegalArgumentException in section1), 38 | // resulting in "A RuntimeException occurred" 39 | assertEquals("A RuntimeException occurred", Jedi.section8(3)); 40 | 41 | // Test case with n = 5 (which should throw NullPointerException in section1), 42 | // resulting in "A RuntimeException occurred" 43 | assertEquals("A RuntimeException occurred", Jedi.section8(5)); 44 | 45 | // Test case with n = 6 (no exception should occur), expecting "No exception occurred" 46 | assertEquals("No exception occurred", Jedi.section8(6)); 47 | } 48 | 49 | /** Test for section9 method */ 50 | @Test 51 | public void testSection9() { 52 | // Test case where n = -1, should catch NegativeValueException and section1(-n) should throw a 53 | // RuntimeException, hence expecting "Two exceptions were caught" 54 | assertEquals("Two exceptions were caught", Jedi.section9(-1)); 55 | 56 | // Test case where n = -7, should catch NegativeValueException but section1(7) will not throw, 57 | // hence expecting "One exception was caught" 58 | assertEquals("One exception was caught", Jedi.section9(-7)); 59 | 60 | // Test case with n = 5 (section7 does not throw, but section1 throws NullPointerException), 61 | // expecting "No exceptions were caught" 62 | assertEquals("No exceptions were caught", Jedi.section9(5)); 63 | 64 | // Test case where n = -5, expecting "Two exceptions were caught" because 65 | // section1(-n) should throw UnsupportedOperationException 66 | assertEquals("Two exceptions were caught", Jedi.section9(-5)); 67 | 68 | // Test case with n = 3 (section7 does not throw, but section1 throws IllegalArgumentException), 69 | // should expect "No exceptions were caught" 70 | assertEquals("No exceptions were caught", Jedi.section9(3)); 71 | 72 | // Test case with n = 6 (no exception is expected in both section7 and section1), 73 | // so it should return "No exceptions were caught" 74 | assertEquals("No exceptions were caught", Jedi.section9(6)); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Exceptions/target/classes/com/comp301/a03exceptions/Adept.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/classes/com/comp301/a03exceptions/Adept.class -------------------------------------------------------------------------------- /Exceptions/target/classes/com/comp301/a03exceptions/Jedi.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/classes/com/comp301/a03exceptions/Jedi.class -------------------------------------------------------------------------------- /Exceptions/target/classes/com/comp301/a03exceptions/NegativeValueException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/classes/com/comp301/a03exceptions/NegativeValueException.class -------------------------------------------------------------------------------- /Exceptions/target/classes/com/comp301/a03exceptions/Novice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/classes/com/comp301/a03exceptions/Novice.class -------------------------------------------------------------------------------- /Exceptions/target/classes/com/comp301/a03exceptions/Printer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/classes/com/comp301/a03exceptions/Printer.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest$1.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest$TestPrinter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest$TestPrinter.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/AdeptTest.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/JediTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/JediTest.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest$1.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest$TestPrinter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest$TestPrinter.class -------------------------------------------------------------------------------- /Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Exceptions/target/test-classes/com/comp301/a03exceptions/NoviceTest.class -------------------------------------------------------------------------------- /Inheritance/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.comp301.a01sushi 8 | a01-sushi 9 | 1.0-SNAPSHOT 10 | 11 | a01-sushi 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.11 26 | test 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | maven-clean-plugin 36 | 3.1.0 37 | 38 | 39 | 40 | maven-resources-plugin 41 | 3.0.2 42 | 43 | 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 48 | maven-surefire-plugin 49 | 2.22.1 50 | 51 | 52 | maven-jar-plugin 53 | 3.0.2 54 | 55 | 56 | maven-install-plugin 57 | 2.5.2 58 | 59 | 60 | maven-deploy-plugin 61 | 2.8.2 62 | 63 | 64 | 65 | maven-site-plugin 66 | 3.7.1 67 | 68 | 69 | maven-project-info-reports-plugin 70 | 3.0.0 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Avocado.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents an Avocado ingredient. Avocado is a type of IngredientGeneral with a name, 5 | * cost, calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Avocado extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Avocado ingredient with its name, cost, calories, and whether 11 | * it is vegetarian, rice, or shellfish. 12 | */ 13 | public Avocado() { 14 | super("avocado", 0.24, 42, true, false, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/AvocadoPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents an Avocado ingredient portion. Avocado is a type of 5 | * IngredientPortionGeneral with a name, cost, calories, and whether it is vegetarian, rice, or 6 | * shellfish, etc. 7 | */ 8 | public class AvocadoPortion extends IngredientPortionGeneral { 9 | 10 | /** 11 | * This constructor initializes the Avocado ingredient portion with its amount. 12 | * 13 | * @param amount The amount of Avocado in ounces 14 | */ 15 | public AvocadoPortion(double amount) { 16 | super(new Avocado(), amount); 17 | } 18 | 19 | /** 20 | * This method combines two Avocado ingredient portions into one. 21 | * 22 | * @param other The other Avocado ingredient portion to be combined 23 | * @return The combined Avocado ingredient portion 24 | */ 25 | @Override 26 | public IngredientPortion combine(IngredientPortion other) { 27 | if (other == null) { 28 | return this; 29 | } 30 | 31 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 32 | 33 | if (!isSameIngredient) { 34 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 35 | } 36 | 37 | double newAmount = this.getAmount() + other.getAmount(); 38 | 39 | return new AvocadoPortion(newAmount); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Crab.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Crab ingredient. Crab is a type of IngredientGeneral with a name, cost, 5 | * calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Crab extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Crab ingredient with its name, cost, calories, and whether it 11 | * is vegetarian, rice, or shellfish. 12 | */ 13 | public Crab() { 14 | super("crab", 0.72, 37, false, false, true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/CrabPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Crab ingredient portion. Crab is a type of IngredientPortionGeneral with 5 | * a name, cost, calories, and whether it is vegetarian, rice, or shellfish, etc. 6 | */ 7 | public class CrabPortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Crab ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Crab in ounces 13 | */ 14 | public CrabPortion(double amount) { 15 | super(new Crab(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Crab ingredient portions into one. 20 | * 21 | * @param other The other Crab ingredient portion to be combined 22 | * @return The combined Crab ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new CrabPortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Eel.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents an Eel ingredient. Eel is a type of IngredientGeneral with a name, cost, 5 | * calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Eel extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Eel ingredient with its name, cost, calories, and whether it 11 | * is vegetarian, rice, or shellfish. 12 | */ 13 | public Eel() { 14 | super("eel", 2.15, 82, false, false, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/EelPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents an Eel ingredient portion. Eel is a type of IngredientPortionGeneral with a 5 | * name, cost, calories, and whether it is vegetarian, rice, or shellfish, etc. 6 | */ 7 | public class EelPortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Eel ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Eel in ounces 13 | */ 14 | public EelPortion(double amount) { 15 | super(new Eel(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Eel ingredient portions into one. 20 | * 21 | * @param other The other Eel ingredient portion to be combined 22 | * @return The combined Eel ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new EelPortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Ingredient.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This interface represents an ingredient in a sushi restaurant. Ingredients have a name, cost, 5 | * calories, and whether they are vegetarian, rice, or shellfish. 6 | */ 7 | public interface Ingredient { 8 | /** 9 | * Getter method for the name of the ingredient 10 | * 11 | * @return the name of the ingredient as a String 12 | */ 13 | String getName(); 14 | 15 | /** 16 | * Getter method for the number of calories in one dollar's worth of the ingredient 17 | * 18 | * @return the number of calories per dollar's worth of the ingredient 19 | */ 20 | double getCaloriesPerDollar(); 21 | 22 | /** 23 | * Getter method for the number of calories in one ounce of the ingredient 24 | * 25 | * @return the number of calories per ounce of the ingredient 26 | */ 27 | int getCaloriesPerOunce(); 28 | 29 | /** 30 | * Getter method for the price of one ounce of the ingredient 31 | * 32 | * @return the price per ounce of the ingredient, in dollars 33 | */ 34 | double getPricePerOunce(); 35 | 36 | /** 37 | * Getter method which returns true if the ingredient is vegetarian 38 | * 39 | * @return true if the ingredient is vegetarian; false otherwise 40 | */ 41 | boolean getIsVegetarian(); 42 | 43 | /** 44 | * Getter method which returns true if the ingredient is rice 45 | * 46 | * @return true if the ingredient is rice; false otherwise 47 | */ 48 | boolean getIsRice(); 49 | 50 | /** 51 | * Getter method which returns true if the ingredient is shellfish 52 | * 53 | * @return true if the ingredient is shellfish; false otherwise 54 | */ 55 | boolean getIsShellfish(); 56 | 57 | /** 58 | * Determines whether the ingredient is the same as another ingredient 59 | * 60 | * @return If other is null, returns false; otherwise, compares the name, calories, price (within 61 | * 1 cent), vegetarian, rice, and shellfish properties of the two ingredients. If all of them 62 | * are the same, returns true. If any are different, returns false. 63 | */ 64 | boolean equals(Ingredient other); 65 | } 66 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/IngredientPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This interface represents an ingredient portion. An ingredient portion has an ingredient, an 5 | * amount (in ounces), and methods to get the name, amount, calories, cost, and whether the 6 | * ingredient is vegetarian, rice, or shellfish. 7 | */ 8 | public interface IngredientPortion { 9 | /** 10 | * Getter method for the underlying ingredient instance 11 | * 12 | * @return the underlying ingredient that this is a portion of 13 | */ 14 | Ingredient getIngredient(); 15 | 16 | /** 17 | * Getter method for the number of ounces of the underlying ingredient that this IngredientPortion 18 | * represents 19 | * 20 | * @return the weight, in ounces, of the underlying ingredient 21 | */ 22 | double getAmount(); 23 | 24 | /** 25 | * Getter method for the name of the ingredient 26 | * 27 | * @return the name of the underlying ingredient as a String 28 | */ 29 | String getName(); 30 | 31 | /** 32 | * Getter method for whether the ingredient is vegetarian 33 | * 34 | * @return true if the underlying ingredient is vegitarian; false otherwise 35 | */ 36 | boolean getIsVegetarian(); 37 | 38 | /** 39 | * Getter method which returns true if the ingredient is rice 40 | * 41 | * @return true if the underlying ingredient is rice; false otherwise 42 | */ 43 | boolean getIsRice(); 44 | 45 | /** 46 | * Getter method which returns true if the ingredient is shellfish 47 | * 48 | * @return true if the underlying ingredient is shellfish; false otherwise 49 | */ 50 | boolean getIsShellfish(); 51 | 52 | /** 53 | * Getter method for the number of calories in the portion 54 | * 55 | * @return the unrounded number of calories in the portion 56 | */ 57 | double getCalories(); 58 | 59 | /** 60 | * Getter method for the price of the portion 61 | * 62 | * @return the unrounded price of the portion 63 | */ 64 | double getCost(); 65 | 66 | /** 67 | * Combines the ingredient portion with another portion of the same ingredient, creating a 68 | * combined portion of the ingredient. 69 | * 70 | * @return If other is null, returns this ingredient portion. If the other ingredient portion is 71 | * not the same as this ingredient portion, throws an IllegalArgumentException. Otherwise, 72 | * returns a new ingredient portion, representing the combined amounts of this ingredient 73 | * portion and the other ingredient portion. HINT: Use the equals() method to test equality. 74 | */ 75 | IngredientPortion combine(IngredientPortion other); 76 | } 77 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/IngredientPortionGeneral.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents an ingredient portion. An ingredient portion is a specific amount of an 5 | * ingredient. Ingredient portions are used to represent the ingredients in a sushi roll. 6 | */ 7 | public abstract class IngredientPortionGeneral implements IngredientPortion { 8 | private Ingredient ingredient; 9 | private double amount; 10 | 11 | /** 12 | * This constructor initializes the ingredient portion with its ingredient and amount. 13 | * 14 | * @param ingredient The ingredient of the portion 15 | * @param amount The amount of the ingredient in ounces 16 | */ 17 | public IngredientPortionGeneral(Ingredient ingredient, double amount) { 18 | if (ingredient == null) { 19 | throw new IllegalArgumentException("Ingredient cannot be null"); 20 | } 21 | 22 | if (amount < 0) { 23 | throw new IllegalArgumentException("Amount cannot be negative"); 24 | } 25 | 26 | this.ingredient = ingredient; 27 | this.amount = amount; 28 | } 29 | 30 | /** 31 | * This method returns the ingredient of the portion. 32 | * 33 | * @return The ingredient of the portion 34 | */ 35 | @Override 36 | public Ingredient getIngredient() { 37 | return this.ingredient; 38 | } 39 | 40 | /** 41 | * This method returns the amount of the ingredient portion. 42 | * 43 | * @return The amount of the ingredient in the portion 44 | */ 45 | @Override 46 | public double getAmount() { 47 | return this.amount; 48 | } 49 | 50 | /** 51 | * This method returns the name of the ingredient portion. 52 | * 53 | * @return The name of the ingredient portion 54 | */ 55 | @Override 56 | public String getName() { 57 | return this.ingredient.getName(); 58 | } 59 | 60 | /** 61 | * This method returns whether the ingredient portion is vegetarian. 62 | * 63 | * @return Whether the ingredient portion is vegetarian 64 | */ 65 | @Override 66 | public boolean getIsVegetarian() { 67 | return this.ingredient.getIsVegetarian(); 68 | } 69 | 70 | /** 71 | * This method returns whether the ingredient portion is rice. 72 | * 73 | * @return Whether the ingredient portion is rice 74 | */ 75 | @Override 76 | public boolean getIsRice() { 77 | return this.ingredient.getIsRice(); 78 | } 79 | 80 | /** 81 | * This method returns whether the ingredient portion is shellfish. 82 | * 83 | * @return Whether the ingredient portion is shellfish 84 | */ 85 | @Override 86 | public boolean getIsShellfish() { 87 | return this.ingredient.getIsShellfish(); 88 | } 89 | 90 | /** 91 | * This method returns the number of calories in the ingredient portion. 92 | * 93 | * @return The number of calories in the ingredient portion 94 | */ 95 | @Override 96 | public double getCalories() { 97 | return this.ingredient.getCaloriesPerOunce() * amount; 98 | } 99 | 100 | /** 101 | * This method returns the cost of the ingredient portion. 102 | * 103 | * @return The cost of the ingredient portion 104 | */ 105 | @Override 106 | public double getCost() { 107 | return this.ingredient.getPricePerOunce() * amount; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Rice.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Rice ingredient. Rice is a type of IngredientGeneral with a name, cost, 5 | * calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Rice extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Rice ingredient with its name, cost, calories, and whether it 11 | * is vegetarian, rice, or shellfish. 12 | */ 13 | public Rice() { 14 | super("rice", 0.13, 34, true, true, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/RicePortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Rice ingredient portion. Rice is a type of IngredientPortionGeneral with 5 | * a name, cost, calories, and whether it is vegetarian, rice, or shellfish, etc. 6 | */ 7 | public class RicePortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Rice ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Rice in ounces 13 | */ 14 | public RicePortion(double amount) { 15 | super(new Rice(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Rice ingredient portions into one. 20 | * 21 | * @param other The other Rice ingredient portion to be combined 22 | * @return The combined Rice ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new RicePortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Seaweed.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Seaweed ingredient. Seaweed is a type of IngredientGeneral with a name, 5 | * cost, calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Seaweed extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Seaweed ingredient with its name, cost, calories, and whether 11 | * it is vegetarian, rice, or shellfish. 12 | */ 13 | public Seaweed() { 14 | super("seaweed", 2.85, 105, true, false, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/SeaweedPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Seaweed ingredient portion. Seaweed is a type of IngredientPortionGeneral 5 | * with a name, cost, calories, and whether it is vegetarian, rice, or shellfish, etc. 6 | */ 7 | public class SeaweedPortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Seaweed ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Seaweed in ounces 13 | */ 14 | public SeaweedPortion(double amount) { 15 | super(new Seaweed(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Seaweed ingredient portions into one. 20 | * 21 | * @param other The other Seaweed ingredient portion to be combined 22 | * @return The combined Seaweed ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new SeaweedPortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Shrimp.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Shrimp ingredient. Shrimp is a type of IngredientGeneral with a name, 5 | * cost, calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Shrimp extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Shrimp ingredient with its name, cost, calories, and whether 11 | * it is vegetarian, rice, or shellfish. 12 | */ 13 | public Shrimp() { 14 | super("shrimp", 0.65, 32, false, false, true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/ShrimpPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Shrimp ingredient portion. Shrimp is a type of IngredientPortionGeneral 5 | * with a name, cost, calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class ShrimpPortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Shrimp ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Shrimp in the portion 13 | */ 14 | public ShrimpPortion(double amount) { 15 | super(new Shrimp(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Shrimp ingredient portions into one portion. 20 | * 21 | * @param other The other Shrimp ingredient portion to be combined 22 | * @return The combined Shrimp ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new ShrimpPortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Sushi.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This interface represents a plate of sushi. A plate of sushi has a name, a list of ingredients, a 5 | * number of calories, a cost, and whether it has rice, shellfish, and is vegetarian. 6 | */ 7 | public interface Sushi { 8 | /** 9 | * Getter method for the name of the sushi 10 | * 11 | * @return the name of the sushi as a String 12 | */ 13 | String getName(); 14 | 15 | /** 16 | * Getter method for the list of ingredients in the plate of sushi 17 | * 18 | * @return the list of ingredients in the plate of sushi 19 | */ 20 | IngredientPortion[] getIngredients(); 21 | 22 | /** 23 | * Getter method for the overall number of calories in the plate of sushi 24 | * 25 | * @return the number of calories in the plate of sushi, rounded to the nearest integer 26 | */ 27 | int getCalories(); 28 | 29 | /** 30 | * Getter method for the cost of the ingredients in the plate of sushi 31 | * 32 | * @return the cost of the ingredients in the plate of sushi, rounded to the nearest cent 33 | */ 34 | double getCost(); 35 | 36 | /** 37 | * Getter method which returns true if the plate of sushi has rice as an ingredient 38 | * 39 | * @return true if the sushi has rice as an ingredient; false otherwise 40 | */ 41 | boolean getHasRice(); 42 | 43 | /** 44 | * Getter method which returns true if the plate of sushi has shellfish as an ingredient 45 | * 46 | * @return true if the sushi has shellfish as an ingredient; false otherwise 47 | */ 48 | boolean getHasShellfish(); 49 | 50 | /** 51 | * Getter method which returns true if the plate of sushi is vegetarian 52 | * 53 | * @return true if all the ingredients in the sushi are vegetarian; false otherwise 54 | */ 55 | boolean getIsVegetarian(); 56 | } 57 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Tuna.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Tuna ingredient. Tuna is a type of IngredientGeneral with a name, cost, 5 | * calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Tuna extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Tuna ingredient with its name, cost, calories, and whether it 11 | * is vegetarian, rice, or shellfish. 12 | */ 13 | public Tuna() { 14 | super("tuna", 1.67, 42, false, false, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/TunaPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Tuna ingredient portion. Tuna is a type of IngredientPortionGeneral with 5 | * a name, cost, calories, and whether it is vegetarian, rice, or shellfish, etc. 6 | */ 7 | public class TunaPortion extends IngredientPortionGeneral { 8 | 9 | /** 10 | * This constructor initializes the Tuna ingredient portion with its amount. 11 | * 12 | * @param amount The amount of Tuna in ounces 13 | */ 14 | public TunaPortion(double amount) { 15 | super(new Tuna(), amount); 16 | } 17 | 18 | /** 19 | * This method combines two Tuna ingredient portions into one. 20 | * 21 | * @param other The other Tuna ingredient portion to be combined 22 | * @return The combined Tuna ingredient portion 23 | */ 24 | @Override 25 | public IngredientPortion combine(IngredientPortion other) { 26 | if (other == null) { 27 | return this; 28 | } 29 | 30 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 31 | 32 | if (!isSameIngredient) { 33 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 34 | } 35 | 36 | double newAmount = this.getAmount() + other.getAmount(); 37 | 38 | return new TunaPortion(newAmount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/Yellowtail.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Yellowtail ingredient. Yellowtail is a type of IngredientGeneral with a 5 | * name, cost, calories, and whether it is vegetarian, rice, or shellfish. 6 | */ 7 | public class Yellowtail extends IngredientGeneral { 8 | 9 | /** 10 | * This constructor initializes the Yellowtail ingredient with its name, cost, calories, and 11 | * whether it is vegetarian, rice, or shellfish. 12 | */ 13 | public Yellowtail() { 14 | super("yellowtail", 0.74, 57, false, false, false); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Inheritance/src/main/java/com/comp301/a01sushi/YellowtailPortion.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | /** 4 | * This class represents a Yellowtail ingredient portion. Yellowtail is a type of 5 | * IngredientPortionGeneral with a name, cost, calories, and whether it is vegetarian, rice, or 6 | * shellfish, etc. 7 | */ 8 | public class YellowtailPortion extends IngredientPortionGeneral { 9 | 10 | /** This constructor initializes the Yellowtail ingredient portion with its amount. */ 11 | public YellowtailPortion(double amount) { 12 | super(new Yellowtail(), amount); 13 | } 14 | 15 | /** 16 | * This method combines two Yellowtail ingredient portions into one portion. 17 | * 18 | * @param other The other Yellowtail ingredient portion to be combined 19 | * @return The combined Yellowtail ingredient portion 20 | */ 21 | @Override 22 | public IngredientPortion combine(IngredientPortion other) { 23 | if (other == null) { 24 | return this; 25 | } 26 | 27 | boolean isSameIngredient = this.getIngredient().equals(other.getIngredient()); 28 | 29 | if (!isSameIngredient) { 30 | throw new IllegalArgumentException("Cannot combine ingredients of different types"); 31 | } 32 | 33 | double newAmount = this.getAmount() + other.getAmount(); 34 | 35 | return new YellowtailPortion(newAmount); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Inheritance/src/test/java/com/comp301/a01sushi/NigiriTest.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | /** This class tests the Nigiri class and its subclasses: Tuna, Yellowtail, Crab, and Shrimp. */ 7 | public class NigiriTest { 8 | 9 | /** This test method tests the creation of Nigiri objects and their respective methods. */ 10 | @Test 11 | public void testNigiriCreation() { 12 | // Case 1: Tuna 13 | Nigiri tunaNigiri = new Nigiri(Nigiri.NigiriType.TUNA); 14 | assertEquals("tuna nigiri", tunaNigiri.getName()); 15 | assertEquals(2, tunaNigiri.getIngredients().length); 16 | assertEquals("tuna", tunaNigiri.getIngredients()[0].getName()); 17 | assertEquals("rice", tunaNigiri.getIngredients()[1].getName()); 18 | assertEquals(49, tunaNigiri.getCalories()); 19 | assertEquals(1.3175, tunaNigiri.getCost(), 0.001); 20 | 21 | // Case 2: Yellowtail 22 | Nigiri yellowtailNigiri = new Nigiri(Nigiri.NigiriType.YELLOWTAIL); 23 | assertEquals("yellowtail nigiri", yellowtailNigiri.getName()); 24 | assertEquals(2, yellowtailNigiri.getIngredients().length); 25 | assertEquals("yellowtail", yellowtailNigiri.getIngredients()[0].getName()); 26 | assertEquals("rice", yellowtailNigiri.getIngredients()[1].getName()); 27 | assertEquals(60, yellowtailNigiri.getCalories()); 28 | assertEquals(0.62, yellowtailNigiri.getCost(), 0.001); 29 | } 30 | 31 | /** This test method tests the getIsVegetarian method in the Nigiri class. */ 32 | @Test 33 | public void testVegetarianCheck() { 34 | // Test case 1: shrimp 35 | Nigiri shrimpNigiri = new Nigiri(Nigiri.NigiriType.SHRIMP); 36 | assertFalse(shrimpNigiri.getIsVegetarian()); 37 | 38 | // Test case 2: yellowtail 39 | Nigiri yellowtailNigiri = new Nigiri(Nigiri.NigiriType.YELLOWTAIL); 40 | assertFalse(yellowtailNigiri.getIsVegetarian()); 41 | } 42 | 43 | /** This test method tests the getHasRice method in the Nigiri class. */ 44 | @Test 45 | public void testHasRice() { 46 | Nigiri yellowtailNigiri = new Nigiri(Nigiri.NigiriType.YELLOWTAIL); 47 | assertTrue(yellowtailNigiri.getHasRice()); 48 | } 49 | 50 | /** This test method tests the getHasShellfish method in the Nigiri class. */ 51 | @Test 52 | public void testHasShellfish() { 53 | // Test case 1: crab 54 | Nigiri crabNigiri = new Nigiri(Nigiri.NigiriType.CRAB); 55 | assertTrue(crabNigiri.getHasShellfish()); 56 | 57 | // Test case 2: eel 58 | Nigiri eelNigiri = new Nigiri(Nigiri.NigiriType.EEL); 59 | assertFalse(eelNigiri.getHasShellfish()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Inheritance/src/test/java/com/comp301/a01sushi/SashimiTest.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a01sushi; 2 | 3 | import static org.junit.Assert.*; 4 | import org.junit.Test; 5 | 6 | /** This class tests the Sashimi class's methods and constructors. */ 7 | public class SashimiTest { 8 | 9 | /** This test method tests the creation of Sashimi objects and their respective methods. */ 10 | @Test 11 | public void testSashimiCreation() { 12 | // Case 1: Tuna 13 | Sashimi tunaSashimi = new Sashimi(Sashimi.SashimiType.TUNA); 14 | assertEquals("tuna sashimi", tunaSashimi.getName()); 15 | assertEquals(1, tunaSashimi.getIngredients().length); 16 | assertEquals("tuna", tunaSashimi.getIngredients()[0].getName()); 17 | assertEquals(32, tunaSashimi.getCalories()); 18 | assertEquals(1.2525, tunaSashimi.getCost(), 0.001); 19 | 20 | // Case 2: Eel 21 | Sashimi eelSashimi = new Sashimi(Sashimi.SashimiType.EEL); 22 | assertEquals("eel sashimi", eelSashimi.getName()); 23 | assertEquals(1, eelSashimi.getIngredients().length); 24 | assertEquals("eel", eelSashimi.getIngredients()[0].getName()); 25 | assertEquals(62, eelSashimi.getCalories()); 26 | assertEquals(1.6125, eelSashimi.getCost(), 0.001); 27 | } 28 | 29 | /** This test method tests the getIsVegetarian method in the Sashimi class. */ 30 | @Test 31 | public void testVegetarianCheck() { 32 | // Test case 1: shrimp 33 | Sashimi shrimpSashimi = new Sashimi(Sashimi.SashimiType.SHRIMP); 34 | assertFalse(shrimpSashimi.getIsVegetarian()); 35 | 36 | // Test case 2: crab 37 | Sashimi crabSashimi = new Sashimi(Sashimi.SashimiType.CRAB); 38 | assertFalse(crabSashimi.getIsVegetarian()); 39 | } 40 | 41 | /** This test method tests the getHasRice method in the Sashimi class. */ 42 | @Test 43 | public void testHasRice() { 44 | Sashimi eelSashimi = new Sashimi(Sashimi.SashimiType.EEL); 45 | assertFalse(eelSashimi.getHasRice()); 46 | } 47 | 48 | /** This test method tests the getHasShellfish method in the Sashimi class. */ 49 | @Test 50 | public void testHasShellfish() { 51 | // Case 1: Crab 52 | Sashimi crabSashimi = new Sashimi(Sashimi.SashimiType.CRAB); 53 | assertTrue(crabSashimi.getHasShellfish()); 54 | 55 | // Case 2: Tuna 56 | Sashimi tunaSashimi = new Sashimi(Sashimi.SashimiType.TUNA); 57 | assertFalse(tunaSashimi.getHasShellfish()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Avocado.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Avocado.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/AvocadoPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/AvocadoPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Crab.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Crab.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/CrabPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/CrabPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Eel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Eel.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/EelPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/EelPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Ingredient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Ingredient.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/IngredientGeneral.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/IngredientGeneral.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/IngredientPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/IngredientPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/IngredientPortionGeneral.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/IngredientPortionGeneral.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Nigiri$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Nigiri$1.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Nigiri$NigiriType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Nigiri$NigiriType.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Nigiri.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Nigiri.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Rice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Rice.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/RicePortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/RicePortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Roll.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Roll.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Sashimi$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Sashimi$1.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Sashimi$SashimiType.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Sashimi$SashimiType.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Sashimi.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Sashimi.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Seaweed.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Seaweed.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/SeaweedPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/SeaweedPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Shrimp.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Shrimp.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/ShrimpPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/ShrimpPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Sushi.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Sushi.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Tuna.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Tuna.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/TunaPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/TunaPortion.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/Yellowtail.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/Yellowtail.class -------------------------------------------------------------------------------- /Inheritance/target/classes/com/comp301/a01sushi/YellowtailPortion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/classes/com/comp301/a01sushi/YellowtailPortion.class -------------------------------------------------------------------------------- /Inheritance/target/test-classes/com/comp301/a01sushi/IngredientPortionTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/test-classes/com/comp301/a01sushi/IngredientPortionTest.class -------------------------------------------------------------------------------- /Inheritance/target/test-classes/com/comp301/a01sushi/IngredientTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/test-classes/com/comp301/a01sushi/IngredientTest.class -------------------------------------------------------------------------------- /Inheritance/target/test-classes/com/comp301/a01sushi/NigiriTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/test-classes/com/comp301/a01sushi/NigiriTest.class -------------------------------------------------------------------------------- /Inheritance/target/test-classes/com/comp301/a01sushi/RollTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/test-classes/com/comp301/a01sushi/RollTest.class -------------------------------------------------------------------------------- /Inheritance/target/test-classes/com/comp301/a01sushi/SashimiTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Inheritance/target/test-classes/com/comp301/a01sushi/SashimiTest.class -------------------------------------------------------------------------------- /Iterator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.comp301.a05driver 8 | a05-driver 9 | 1.0-SNAPSHOT 10 | 11 | a05-driver 12 | 13 | http://www.example.com 14 | 15 | 16 | UTF-8 17 | 1.7 18 | 1.7 19 | 20 | 21 | 22 | 23 | junit 24 | junit 25 | 4.11 26 | test 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | maven-clean-plugin 36 | 3.1.0 37 | 38 | 39 | 40 | maven-resources-plugin 41 | 3.0.2 42 | 43 | 44 | maven-compiler-plugin 45 | 3.8.0 46 | 47 | 48 | maven-surefire-plugin 49 | 2.22.1 50 | 51 | 52 | maven-jar-plugin 53 | 3.0.2 54 | 55 | 56 | maven-install-plugin 57 | 2.5.2 58 | 59 | 60 | maven-deploy-plugin 61 | 2.8.2 62 | 63 | 64 | 65 | maven-site-plugin 66 | 3.7.1 67 | 68 | 69 | maven-project-info-reports-plugin 70 | 3.0.0 71 | 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-compiler-plugin 78 | 79 | 8 80 | 8 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/Driver.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /* 4 | * Driver 5 | * Represents a driver associated with a vehicle. 6 | * 7 | * getFirstName() 8 | * Retrieves first name of driver. 9 | * 10 | * getLastName() 11 | * Retrieves last name of driver. 12 | * 13 | * getFullName() 14 | * Retrieves full name of driver. This should be the first name followed 15 | * a single space followed by the last name. 16 | * 17 | * getID() 18 | * Retrieves the ID number of the driver. 19 | * 20 | * getVehicle() 21 | * Retrieves the Vehicle object associated with the driver. 22 | * 23 | * setVehicle(Vehicle v) 24 | * Setter for the vehicle associated with the driver. 25 | */ 26 | 27 | /** Represents a driver associated with a vehicle. */ 28 | public interface Driver { 29 | 30 | /** 31 | * Retrieves first name of driver. 32 | * 33 | * @return first name of driver 34 | */ 35 | String getFirstName(); 36 | 37 | /** 38 | * Retrieves last name of driver. 39 | * 40 | * @return last name of driver 41 | */ 42 | String getLastName(); 43 | 44 | /** 45 | * Retrieves full name of driver. This should be the first name followed by a single space 46 | * followed by the last name. 47 | * 48 | * @return full name of driver 49 | */ 50 | default String getFullName() { 51 | return getFirstName() + " " + getLastName(); 52 | } 53 | 54 | /** 55 | * Retrieves the ID number of the driver. 56 | * 57 | * @return ID number of the driver 58 | */ 59 | int getID(); 60 | 61 | /** 62 | * Retrieves the Vehicle object associated with the driver. 63 | * 64 | * @return Vehicle object associated with the driver 65 | */ 66 | Vehicle getVehicle(); 67 | 68 | /** 69 | * Setter for the vehicle associated with the driver. 70 | * 71 | * @param v Vehicle object to associate with the driver 72 | */ 73 | void setVehicle(Vehicle v); 74 | } 75 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/DriverImpl.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /** Represents a driver associated with a vehicle. */ 4 | public class DriverImpl implements Driver { 5 | 6 | private String _first; 7 | private String _last; 8 | private int _id; 9 | private Vehicle _vehicle; 10 | 11 | /** 12 | * Constructor for the DriverImpl class. 13 | * 14 | * @param first The first name of the driver 15 | * @param last The last name of the driver 16 | * @param id The ID number of the driver 17 | * @param vehicle The Vehicle object associated with the driver 18 | */ 19 | public DriverImpl(String first, String last, int id, Vehicle vehicle) { 20 | if (first == null) { 21 | throw new RuntimeException("Null first name"); 22 | } 23 | if (last == null) { 24 | throw new RuntimeException("Null last name"); 25 | } 26 | if (vehicle == null) { 27 | throw new RuntimeException("Null vehicle"); 28 | } 29 | 30 | _first = first; 31 | _last = last; 32 | _id = id; 33 | _vehicle = vehicle; 34 | } 35 | 36 | /** 37 | * Retrieves first name of driver. 38 | * 39 | * @return first name of driver 40 | */ 41 | @Override 42 | public String getFirstName() { 43 | return _first; 44 | } 45 | 46 | /** 47 | * Retrieves last name of driver. 48 | * 49 | * @return last name of driver 50 | */ 51 | @Override 52 | public String getLastName() { 53 | return _last; 54 | } 55 | 56 | /** 57 | * Retrieves the ID number of the driver. 58 | * 59 | * @return ID number of the driver 60 | */ 61 | @Override 62 | public int getID() { 63 | return _id; 64 | } 65 | 66 | /** 67 | * Retrieves the Vehicle object associated with the driver. 68 | * 69 | * @return Vehicle object associated with the driver 70 | */ 71 | @Override 72 | public Vehicle getVehicle() { 73 | return _vehicle; 74 | } 75 | 76 | /** 77 | * Setter for the vehicle associated with the driver. 78 | * 79 | * @param v Vehicle object to associate with the driver 80 | */ 81 | @Override 82 | public void setVehicle(Vehicle v) { 83 | if (v == null) { 84 | throw new RuntimeException("Null vehicle"); 85 | } 86 | _vehicle = v; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/Position.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /* 4 | * Position 5 | * Represents an integer (x,y) position on a grid. 6 | * 7 | * getX() 8 | * Retrieves x coordinate of the position 9 | * 10 | * getY() 11 | * Retrieves y coordinate of the position 12 | * 13 | * getManhattanDistanceTo(Position p) 14 | * Calculates the "Manhattan" distance between two positions. 15 | * The Manhattan distance is simply the absolute difference in x positions 16 | * summed with the absolute difference in y positions. 17 | */ 18 | 19 | /** Represents an integer (x,y) position on a grid. */ 20 | public interface Position { 21 | 22 | /** 23 | * Retrieves x coordinate of the position 24 | * 25 | * @return x coordinate of the position 26 | */ 27 | int getX(); 28 | 29 | /** 30 | * Retrieves y coordinate of the position 31 | * 32 | * @return y coordinate of the position 33 | */ 34 | int getY(); 35 | 36 | /** 37 | * Calculates the "Manhattan" distance between two positions. The Manhattan distance is simply the 38 | * absolute difference in x positions summed with the absolute difference in y positions. 39 | * 40 | * @param p The other position to calculate the distance to 41 | * @return The Manhattan distance between the two positions 42 | */ 43 | default int getManhattanDistanceTo(Position p) { 44 | return Math.abs(getX() - p.getX()) + Math.abs(getY() - p.getY()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/PositionImpl.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /** Represents an integer (x,y) position on a grid. */ 4 | public class PositionImpl implements Position { 5 | 6 | private int _x; 7 | private int _y; 8 | 9 | /** 10 | * Constructor for the PositionImpl class. 11 | * 12 | * @param x The x coordinate of the position 13 | * @param y The y coordinate of the position 14 | */ 15 | public PositionImpl(int x, int y) { 16 | _x = x; 17 | _y = y; 18 | } 19 | 20 | /** 21 | * Retrieves x coordinate of the position 22 | * 23 | * @return x coordinate of the position 24 | */ 25 | @Override 26 | public int getX() { 27 | return _x; 28 | } 29 | 30 | /** 31 | * Retrieves y coordinate of the position 32 | * 33 | * @return y coordinate of the position 34 | */ 35 | @Override 36 | public int getY() { 37 | return _y; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /* 4 | * Vehicle 5 | * Represents a vehicle in our system. 6 | * 7 | * getMake() 8 | * Retrieves the make of the vehicle. 9 | * 10 | * getModel() 11 | * Retrieves the model of the vehicle. 12 | * 13 | * getPlate() 14 | * Retrieves the license plate of the vehicle. 15 | * 16 | * getMileage() 17 | * Retrieves the total distance the vehicle has traveled 18 | * up to now. Think of this like its "odometer". 19 | * 20 | * getPosition() 21 | * Retrieves the current position of the vehicle. 22 | * 23 | * moveTo(Position p) 24 | * Updates the mileage of the vehicle by adding the Manhattan 25 | * distance between the vehicle's current position and the 26 | * position p passed in as a parameter. Then updates the 27 | * vehicle's current position to be p. 28 | */ 29 | 30 | /** Represents a vehicle in our system. */ 31 | public interface Vehicle { 32 | 33 | /** 34 | * Retrieves the make of the vehicle. 35 | * 36 | * @return The make of the vehicle 37 | */ 38 | String getMake(); 39 | 40 | /** 41 | * Retrieves the model of the vehicle. 42 | * 43 | * @return The model of the vehicle 44 | */ 45 | String getModel(); 46 | 47 | /** 48 | * Retrieves the license plate of the vehicle. 49 | * 50 | * @return The license plate of the vehicle 51 | */ 52 | String getPlate(); 53 | 54 | /** 55 | * Retrieves the total distance the vehicle has traveled up to now. Think of this like its 56 | * "odometer". 57 | * 58 | * @return The total distance the vehicle has traveled 59 | */ 60 | int getMileage(); 61 | 62 | /** 63 | * Retrieves the current position of the vehicle. 64 | * 65 | * @return The current position of the vehicle 66 | */ 67 | Position getPosition(); 68 | 69 | /** 70 | * Updates the mileage of the vehicle by adding the Manhattan distance between the vehicle's 71 | * current position and the position p passed in as a parameter. Then updates the vehicle's 72 | * current position to be p. 73 | * 74 | * @param p The position to move the vehicle to 75 | */ 76 | void moveToPosition(Position p); 77 | } 78 | -------------------------------------------------------------------------------- /Iterator/src/main/java/com/comp301/a05driver/VehicleImpl.java: -------------------------------------------------------------------------------- 1 | package com.comp301.a05driver; 2 | 3 | /** Represents a vehicle that can be driven by a driver. */ 4 | public class VehicleImpl implements Vehicle { 5 | 6 | private String _make; 7 | private String _model; 8 | private String _plate; 9 | private int _mileage; 10 | private Position _position; 11 | 12 | /** 13 | * Constructor for the VehicleImpl class. 14 | * 15 | * @param make The make of the vehicle 16 | * @param model The model of the vehicle 17 | * @param plate The license plate of the vehicle 18 | * @param position The current position of the vehicle 19 | */ 20 | public VehicleImpl(String make, String model, String plate, Position position) { 21 | if (make == null) { 22 | throw new RuntimeException("make is null"); 23 | } 24 | if (model == null) { 25 | throw new RuntimeException("model is null"); 26 | } 27 | if (plate == null) { 28 | throw new RuntimeException("plate is null"); 29 | } 30 | if (position == null) { 31 | throw new RuntimeException("position is null"); 32 | } 33 | 34 | _make = make; 35 | _model = model; 36 | _plate = plate; 37 | _position = position; 38 | 39 | _mileage = 0; 40 | } 41 | 42 | /** 43 | * Retrieves the make of the vehicle. 44 | * 45 | * @return The make of the vehicle 46 | */ 47 | @Override 48 | public String getMake() { 49 | return _make; 50 | } 51 | 52 | /** 53 | * Retrieves the model of the vehicle. 54 | * 55 | * @return The model of the vehicle 56 | */ 57 | @Override 58 | public String getModel() { 59 | return _model; 60 | } 61 | 62 | /** 63 | * Retrieves the license plate of the vehicle. 64 | * 65 | * @return The license plate of the vehicle 66 | */ 67 | @Override 68 | public String getPlate() { 69 | return _plate; 70 | } 71 | 72 | /** 73 | * Retrieves the total distance the vehicle has traveled up to now. Think of this like its 74 | * "odometer". 75 | * 76 | * @return The total distance the vehicle has traveled 77 | */ 78 | @Override 79 | public int getMileage() { 80 | return _mileage; 81 | } 82 | 83 | /** 84 | * Retrieves the current position of the vehicle. 85 | * 86 | * @return The current position of the vehicle 87 | */ 88 | @Override 89 | public Position getPosition() { 90 | return _position; 91 | } 92 | 93 | /** 94 | * Updates the mileage of the vehicle by adding the Manhattan distance between the vehicle's 95 | * current position and the position p passed in as a parameter. Then updates the vehicle's 96 | * current position to be p. 97 | * 98 | * @param p The new position of the vehicle 99 | */ 100 | @Override 101 | public void moveToPosition(Position p) { 102 | if (p == null) { 103 | throw new RuntimeException("New vehicle position is null"); 104 | } 105 | 106 | _mileage += _position.getManhattanDistanceTo(p); 107 | _position = p; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/Driver.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/Driver.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/DriverImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/DriverImpl.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/ExpandingProximityIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/ExpandingProximityIterator.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/Position.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/Position.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/PositionImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/PositionImpl.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/ProximityIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/ProximityIterator.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/SnakeOrderAcrossPoolsIterator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/SnakeOrderAcrossPoolsIterator.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/Vehicle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/Vehicle.class -------------------------------------------------------------------------------- /Iterator/target/classes/com/comp301/a05driver/VehicleImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/classes/com/comp301/a05driver/VehicleImpl.class -------------------------------------------------------------------------------- /Iterator/target/test-classes/com/comp301/a05driver/ExpandingProximityIteratorTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/test-classes/com/comp301/a05driver/ExpandingProximityIteratorTest.class -------------------------------------------------------------------------------- /Iterator/target/test-classes/com/comp301/a05driver/ProximityIteratorTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/test-classes/com/comp301/a05driver/ProximityIteratorTest.class -------------------------------------------------------------------------------- /Iterator/target/test-classes/com/comp301/a05driver/SnakeOrderAcrossPoolsIteratorTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Iterator/target/test-classes/com/comp301/a05driver/SnakeOrderAcrossPoolsIteratorTest.class -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Son Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Son Nguyen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/img/instructions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/img/instructions.png -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/img/ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/img/ui.png -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/img/welcome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/img/welcome.png -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | Game-2048-JavaFX 9 | 1.0-SNAPSHOT 10 | Game-2048-JavaFX 11 | 12 | 13 | UTF-8 14 | 5.10.2 15 | 16 | 17 | 18 | 19 | org.openjfx 20 | javafx-controls 21 | 22.0.1 22 | 23 | 24 | org.openjfx 25 | javafx-fxml 26 | 22.0.1 27 | 28 | 29 | 30 | org.junit.jupiter 31 | junit-jupiter-api 32 | ${junit.version} 33 | test 34 | 35 | 36 | junit 37 | junit 38 | 4.11 39 | test 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter-engine 44 | ${junit.version} 45 | test 46 | 47 | 48 | org.mongodb 49 | mongodb-driver-sync 50 | 4.9.0 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-compiler-plugin 59 | 3.13.0 60 | 61 | 22 62 | 22 63 | 64 | 65 | 66 | org.openjfx 67 | javafx-maven-plugin 68 | 0.0.8 69 | 70 | 71 | 72 | default-cli 73 | 74 | org.example.game2048javafx/org.example.game2048javafx.HelloApplication 75 | app 76 | app 77 | app 78 | true 79 | true 80 | true 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module org.example.game2048javafx { 2 | requires javafx.controls; 3 | requires javafx.fxml; 4 | 5 | 6 | opens org.example.game2048javafx to javafx.fxml; 7 | exports org.example.game2048javafx; 8 | } -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/java/org/example/game2048javafx/Controller.java: -------------------------------------------------------------------------------- 1 | package org.example.game2048javafx; 2 | 3 | /** The Controller class is responsible for handling user input and updating the model and view */ 4 | public class Controller { 5 | 6 | /** The model of the game */ 7 | private final Model model; 8 | 9 | /** The view of the game */ 10 | private final View view; 11 | 12 | /** 13 | * Constructor for the Controller class 14 | * 15 | * @param model The model of the game 16 | * @param view The view of the game 17 | */ 18 | public Controller(Model model, View view) { 19 | this.model = model; 20 | this.view = view; 21 | } 22 | 23 | /** Starts the game by resetting the board and adding two random tiles */ 24 | public void startGame() { 25 | model.resetBoard(); 26 | model.addRandomTile(); 27 | model.addRandomTile(); 28 | view.updateUI(model.getBoard(), model.getScore(), model.getBestScore()); 29 | } 30 | 31 | /** 32 | * Handles the key press event by moving the tiles in the specified direction 33 | * 34 | * @param direction The direction to move the tiles 35 | */ 36 | public void handleKeyPress(String direction) { 37 | if (model.move(direction)) { 38 | model.addRandomTile(); 39 | view.updateUI(model.getBoard(), model.getScore(), model.getBestScore()); 40 | if (model.checkGameOver()) { 41 | System.out.println("Game Over!"); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/favicon.png -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Black.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Black.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-BlackItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-BlackItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Bold.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-BoldItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraBold.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraBoldItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraLight.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraLight.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraLightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ExtraLightItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Italic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Light.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-LightItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Medium.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-MediumItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-MediumItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Regular.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-SemiBold.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Thin.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-Thin.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ThinItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangsonww/Software-Design-Patterns/6d0784d1108ce1a638a585b9126bfff7d3e12b56/Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/fonts/Poppins-ThinItalic.ttf -------------------------------------------------------------------------------- /Model-View-Controllers/Game-2048-JavaFX/src/main/resources/org/example/game2048javafx/hello-view.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 |