This project simulates a kitchen delivery system where orders are prepared, dispatched to couriers, and delivered based on different strategies.
The project consists of several Java classes organized into packages:
- com.cloud.kitchen: Contains the main application classes and entry point.
- com.cloud.kitchen.factory: Includes the
CourierFactory
class for creating courier objects. - com.cloud.kitchen.mediator: Contains the
KitchenMediator
class responsible for managing orders, couriers, and dispatch strategies. - com.cloud.kitchen.models: Includes the
Order
andCourier
classes representing orders and couriers respectively. - com.cloud.kitchen.observer: Defines observer interfaces (
MediatorSubject
,OrderReadyObserver
,CourierArrivalObserver
) for handling events related to orders and couriers. - com.cloud.kitchen.strategy: Contains different strategies (
OrderDispatcherStrategy
,MatchedOrderDispatcherStrategy
,FifoOrderDispatcherStrategy
) for dispatching orders.
- Visit Oracle's Java SE Downloads page or OpenJDK's AdoptOpenJDK to download the JDK appropriate for your operating system.
- Follow the installation instructions provided for your OS.
- Visit Apache Maven's download page and download the latest Maven binary zip file.
- Extract the downloaded zip file to a directory of your choice.
setx MAVEN_HOME "path_to_your_maven_directory"
setx PATH "%PATH%;%MAVEN_HOME%\bin"
Close and reopen any command prompt windows after setting the environment variables.
Add the following lines to your ~/.bash_profile or ~/.bashrc file:
export MAVEN_HOME=path_to_your_maven_directory
export PATH=$PATH:$MAVEN_HOME/bin
Run source ~/.bash_profile or source ~/.bashrc to apply the changes in the current terminal.
To run the project, follow these steps:
- Java Development Kit (JDK): Version 8 or above. You can download it from Oracle's JDK website or use OpenJDK
- Maven build tool installed
-
Clone the repository:
cd CloudKitchenCodingProject
-
Build the project:
mvn clean install
-
Run the main application: Replace target/CloudKitchenCodingProject-1.0.jar with the actual path to the generated JAR file if it differs.
java -cp target/CloudKitchenCodingProject-1.0.jar com.cloud.kitchen.Main
-
Testing: Unit tests are available in the src/test directory. You can run them using Maven:
mvn test
-
Expected Output: The application simulates order preparation, courier dispatch, and delivery based on configured strategies. Logs will show information about order handling, dispatch times, and average wait times for food and couriers.
-
Troubleshooting: If any errors occur during setup or execution, check Maven dependencies and ensure the ORDERS_FILE (dispatch_orders.json) is accessible in the expected location (src/main/resources).
-
Customization: Modify dispatch strategies (FifoOrderDispatcherStrategy, MatchedOrderDispatcherStrategy) or add new strategies in com.cloud.kitchen.stragety package as per your requirements.
-
Java Development Kit (JDK):
- Ensure JDK is installed. You can download it from Oracle's Java SE Downloads or OpenJDK.
-
IntelliJ IDEA:
- Download and install IntelliJ IDEA from here.
-
Open Project:
- Launch IntelliJ IDEA.
- Click on File -> Open and navigate to your Java project directory.
-
Import Project from Existing Sources:
- Select the
pom.xml
file (Maven projects) or the root directory containing your Java project. - Click Open to import the project.
- Select the
-
Configure JDK in IntelliJ IDEA:
- Go to File -> Project Structure.
- Under Project Settings, select Project.
- Set the Project SDK to the installed JDK.
-
Configure Maven in IntelliJ IDEA (for Maven projects):
- Go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven.
- Set Maven home directory to the directory where Maven is installed.
-
Run the Main Class:
- In the Project tool window, navigate to your main class (usually located in
src/main/java
). - Right-click on the main class and select Run or Debug.
- In the Project tool window, navigate to your main class (usually located in
-
View Output:
- The output will be displayed in the Run tool window at the bottom of IntelliJ IDEA.
-
Set Breakpoints:
- Click in the gutter next to a line of code to set a breakpoint.
-
Debug Java Application:
- Open the Java file with breakpoints set.
- Right-click in the editor and choose Debug.
- Use the debug controls (
F8
for step over,F7
for step into, etc.).
-
Java Development Kit (JDK):
- Ensure JDK is installed. You can download it from Oracle's Java SE Downloads or OpenJDK.
-
Visual Studio Code:
- Download and install Visual Studio Code from here.
-
Java Extension Pack:
- Open Visual Studio Code.
- Go to Extensions (or press
Ctrl+Shift+X
), search for "Java Extension Pack", and click "Install".
-
Open Project Folder:
- Launch Visual Studio Code.
- Click on File -> Open Folder and select your Java project folder.
-
Configure JDK in Visual Studio Code:
- Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
on macOS). - Type "Java: Configure Java Runtime" and select it.
- Choose the installed JDK.
- Open the Command Palette (
-
Create or Open Java Files:
- Navigate to your Java source code (
src
folder). - Create new Java files or open existing ones.
- Navigate to your Java source code (
-
Run Java Application:
- Open the Java file containing the main method.
- Right-click in the editor and choose Run or Debug.
- Alternatively, use the shortcut
Ctrl+F5
to run without debugging.
-
View Output:
- The output will be displayed in the Terminal tab at the bottom of Visual Studio Code.
-
Set Breakpoints:
- Click in the gutter next to a line of code to set a breakpoint.
-
Debug Java Application:
- Open the Java file with breakpoints set.
- Right-click in the editor and choose Debug.
- Use the debug controls (
F5
to start debugging,F10
for step over,F11
for step into, etc.).
-
Java Development Kit (JDK):
- Ensure JDK is installed. You can download it from Oracle's Java SE Downloads or OpenJDK.
-
Eclipse IDE:
- Download and install Eclipse IDE for Java Developers from here.
-
Open Eclipse:
- Launch Eclipse IDE.
-
Import Project:
- If you have an existing project:
- Click on File -> Import -> General -> Existing Projects into Workspace.
- Select your project directory and click Finish.
- If you are creating a new project:
- Click on File -> New -> Java Project.
- Enter a project name and click Finish.
- If you have an existing project:
-
Configure JDK in Eclipse:
- Go to Window -> Preferences -> Java -> Installed JREs.
- Add or select the JDK installed on your system.
-
Run the Main Class:
- In the Project Explorer, navigate to your main class (usually located in the
src
folder). - Right-click on the main class and select Run As -> Java Application.
- In the Project Explorer, navigate to your main class (usually located in the
-
View Output:
- The output will be displayed in the Console view at the bottom of Eclipse.
-
Set Breakpoints:
- Click in the margin next to a line of code to set a breakpoint.
-
Debug Java Application:
- Open the Java file with breakpoints set.
- Right-click in the editor and choose Debug As -> Java Application.
- Use the debug controls (
F8
for step over,F5
for step into, etc.).