You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Java implementation demonstrating the use of Stack and Queue data structures to simulate an elevator system for moving boxes between floors.
4
+
5
+
## Overview
6
+
7
+
The project simulates a building with 5 floors (numbered 0-4) and an elevator system that moves boxes between floors. Each box has a target destination floor, and the elevator's task is to efficiently deliver all boxes to their respective floors.
8
+
9
+
## Implementation Details
10
+
11
+
### Data Structures Used
12
+
13
+
-**Queue**: Represents each floor of the building, holding boxes waiting to be moved
14
+
-**Stack**: Represents the elevator, following LIFO (Last In, First Out) principle
15
+
-**Array**: Used to organize the queues for each floor
16
+
17
+
### Classes
18
+
19
+
1.**MovingBox.java**
20
+
21
+
- Represents a box to be moved
22
+
- Properties:
23
+
- referenceNumber: Unique identifier for each box
24
+
- floor: Target floor for delivery
25
+
26
+
2.**Driver.java**
27
+
- Contains the main simulation logic
28
+
- Creates a building with 5 floors
29
+
- Generates 100 boxes with random destination floors
30
+
- Implements elevator logic using Stack and Queue operations
31
+
32
+
## Algorithm
33
+
34
+
The elevator system follows these rules:
35
+
36
+
1. Maximum capacity of 20 boxes
37
+
2. If elevator is empty, it looks for a floor with waiting boxes
38
+
3. When stopping at a floor:
39
+
- Unloads all boxes
40
+
- Checks each box:
41
+
- If it's at its target floor, marks as delivered
42
+
- If not, loads it back into the elevator
43
+
4. Continues until all boxes are delivered to their target floors
44
+
45
+
## Usage
46
+
47
+
Compile and run the Driver class to start the simulation:
0 commit comments