AI Project: Building a Lift System for a Secure Research Facility

Verified

Added on  2019/09/21

|15
|3388
|174
Project
AI Summary
This assignment requires the development of a lift system for a secure research facility. The system must manage users with ID cards, track their locations, and efficiently allocate lifts based on a suitability function. The building has six floors and three lifts, each serving different floors. The system should handle user registration, removal, and lift calls, including destination selection. The core functionality includes the implementation of a menu-driven interface, lift operation logic, and the calculation of the most suitable lift for each call. The assignment also requires the implementation of different modes to display waiting and idle users and automatically show the lifts. The system should simulate the movement of lifts, handling passengers boarding and alighting, and optimizing the lift's direction based on the current state and user requests. This solution provides a complete implementation of the described lift system, addressing all specified requirements and scenarios.
Document Page
2. Specification
A secure research facility has hired you to
develop a new system for the lifts of its secure
building. The system needs to know where
everyone in the building is at every moment. To
use the lifts, a person must be added to the
system and given an ID card. This ID card must
be swiped when making a trip on the lift so that
the lift can track the movement of that person.
The building has 6 floors and 3 lifts. Each lift
services a different range of levels: Lift 1
services levels 16, Lift 2 services levels 26 and Lift 3 services levels 25. The building
entrance is on level 2 and the initial resting positions of all 3 lifts is level 2.
When a person registers for an ID card, the system records their initial level as 2. A person
can also be removed from the system, but only if they are on level 2 and not currently
waiting for or aboard a lift.
When calling a lift, a person swipes his/her ID card, selects a destination level/floor, and then
waits. The system uses an algorithm to select the most suitable lift and reports the number
of that lift to the caller. When the lift reaches the caller’s current level, the caller boards the
lift unless the lift is heading in the opposite direction to that of the caller’s destination. When
the lift reaches the caller’s destination, the caller alights from the lift. The lift will stop at a
level if any person wants to board or alight.
1
The most suitable lift for a caller is determined by a suitability function. If a lift’s service range
doesn’t include the caller’s current level or destination level, that lift’s suitability is 0.
Otherwise if a lift is moving away from the caller, its suitability is 1. Otherwise if a lift is
moving in the opposite direction that the caller wants to go in, then its suitability is N + 1 D
where N is the highest minus the lowest level of the building and D is the distance in levels
between the lift and the caller. Otherwise, the lift’s suitability is N + 2 D. The most suitable
lift for a caller is the lift with the highest suitability.
An aside...
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
While reading the the first part of the specification, you will notice there is a lot going on.
How many functions did you identify?
How many classes did you identify?
What are the fields in each class?
How many goals did you identify?
How many patterns did you think of that might be applicable?
This assignment will be challenging and you will probably want to manage your time well.
How long do you think it will take you to code the functions?
How long do you think it will take you to code each goal?
A good rule of thumb is to think of an estimate, and then multiply that number by 3 or 4!
To manage your time well, you may need to figure out which parts of the assignment you
can start early.
Which parts can you start now?
Which parts can you start in week 5?
If you complete parts in the same week that you learn the topics (while they are fresh in your
mind), they will take less time to complete.
The User Interface
Below is a sample I/O trace. Not every
conceivable scenario is shown below and
you should submit your code to PLATE to
see what specific scenarios are tested.
Basic usage
When the program launches, you will see a mode prompt which can be used to change the
behaviour of the program.
Mode:
For the moment, let’s leave this blank and press enter. The menu is now shown. Inputting an
unrecognised command results in the help being shown:
Choice (a/r/p/c/l/o/x): ?
2
Menu
a = add person
Document Page
r = remove person
p = show people
c = call lift
l = show lifts
o = operate
The user can add, remove and show people registered in the system with the ‘a’, ‘r’ and ‘p’
options. Each person must have a unique ID:
Choice (a/r/p/c/l/o/x): a
Person ID: 1
Name: Sam Worthington
Choice (a/r/p/c/l/o/x): a
Person ID: 1
ID already exists
Choice (a/r/p/c/l/o/x): a
Person ID: 2
Name: Nicole Kidman
Choice (a/r/p/c/l/o/x): a
Person ID: 3
Name: Hugh Jackman
Choice (a/r/p/c/l/o/x): p
Sam Worthington(1) on level 2
Nicole Kidman(2) on level 2
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): r
Person ID: 1
Choice (a/r/p/c/l/o/x): r
Person ID: 1
No such person
Choice (a/r/p/c/l/o/x): p
Nicole Kidman(2) on level 2
Hugh Jackman(3) on level 2
Document Page
The lifts are shown with the ‘l’ option:
Choice (a/r/p/c/l/o/x): l
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Each lift is displayed as a string of dashes with the left side representing the bottom of the lift
and the right side representing the top of the lift. One of the dashes is replaced by a number
indicating how many passengers are currently aboard that lift. The position of this number
also indicates the location of the lift within the shaft. Notice that Lift 2 and Lift 3 are shifted
right by one level because those lifts start at level 2. Your code must not have any special
cases to deal with different lifts. For example, you cannot write code like this: if (liftNumber !=
1) { add an extra space }.
3
A lift can be called with the ‘c’ option:
Choice (a/r/p/c/l/o/x): c
Person ID: 1
No such ID
Choice (a/r/p/c/l/o/x): c
Person ID: 2
Destination level: 4
Choice (a/r/p/c/l/o/x): p
Nicole Kidman(2) on level 2 waiting to go to level 4
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): l
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
The most suitable lift is chosen and the caller is added to the lift’s queue. In this case, all 3
lifts are equally suitable so the first lift will be chosen. If there was no suitable left (e.g. the
destination was not serviceable by any lift), the call is discarded.
The lifts are operated via the ‘o’ option. Here, each lift use this algorithm:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
If the lift is currently stationary, check if there is anyone in the queue to be picked up
or if there is any passenger to be dropped off, and set the direction of the lift toward
the pickup or dropoff point.
Before moving, let any passengers who want to alight here alight (they are then
removed from the passengers list), and let any people in the queue board if they’re
heading in the same direction as the lift and they’re on the same level that the lift is
currently on (they are then removed from the queue).
If the lift is now empty, the lift becomes idle (set the direction to 0).
Otherwise, move the lift and all its passengers one level in the current direction. The
lift stops if it reaches the top or bottom (set the direction to 0).
Now that Nicole has made a call for a lift, the operate option will work as follows:
Choice (a/r/p/c/l/o/x): o
Choice (a/r/p/c/l/o/x): p
Nicole Kidman(2) on level 2 going to level 4
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): l
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
Nicole has boarded lift 1 and is now going UP to level 4, but the lift hasn’t moved yet.
Pressing ‘o’ again:
Choice (a/r/p/c/l/o/x): o
Choice (a/r/p/c/l/o/x): p
4
Nicole Kidman(2) on level 3 going to level 4
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): l
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
The lift has moved up to level 3, and Nicole has moved along with the lift. Again:
Document Page
Choice (a/r/p/c/l/o/x): o
Choice (a/r/p/c/l/o/x): p
Nicole Kidman(2) on level 4 going to level 4
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): l
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
The lift with Nicole have moved up to level 4 and has stopped, but Nicole hasn’t alighted yet.
Again:
Choice (a/r/p/c/l/o/x): o
Choice (a/r/p/c/l/o/x): p
Nicole Kidman(2) on level 4
Hugh Jackman(3) on level 2
Choice (a/r/p/c/l/o/x): l
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Nicole has now alighted and there are zero passengers aboard.
The ‘x’ option exits the program.
Choice (a/r/p/c/l/o/x): x
Modes
When starting the program, the mode prompt allows for the input of a string of special mode
codes in any order.
‘w’ means show how many people are waiting for a lift on each level of the building.
‘i’ means show how many people are idle on each level (i.e. not aboard a lift and not
waiting for a lift).
‘a’ means the lifts will be automatically be displayed along with the program’s main
menu.
For example, if you input “wi” or “iw” as the mode, then the waiting and idle numbers will be
displayed for each level:
Document Page
5
Idle: 1 2
Waiting: 1
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
This indicates that 1 person is idle on level 1, 2 people are idle on level 5 and 1 person is
waiting for a lift on level 3. If the mode is “w”, then just the waiting numbers will be displayed:
Waiting: 1
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Let’s run the program with all mode options enabled:
Mode: iwa
Idle:
Waiting:
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
As you can see, the lifts are automatically shown along with the menu. With the ‘a’ mode
turned on, there is no longer any need to use the ‘l’ option to view the lifts. Also, with the ‘w’
and ‘i’ modes turned on, there is little reason to use the ‘p’ option to view the people. This
allows us to run a scenario just with a combination of the call and operate menu options
(after first adding some people):
Choice (a/r/p/c/l/o/x): a
Person ID: 1
Name: Bridget Jones
Idle: 1
Waiting:
Lift 1 |0|
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x): a
Person ID: 2
Name: Mark Darcy
Idle: 2
Waiting:
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x): c
6
Person ID:
1
Destination level:
3
Idle: 1
Waiting: 1
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
c
Person ID:
2
Destination level:
6
Idle:
Waiting: 2
Lift 1 |0|
Lift 2 |0|
Document Page
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle:
Waiting:
Lift 1 |2| UP
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle:
Waiting:
Lift 1 |2| UP
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Document Page
Idle: 1
Waiting:
Lift 1 |1| UP
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |1|
Lift 2 |0|
Lift 3 |0|
7
Choice (a/r/p/c/l/o/x):
o
Idle: 1 1
Waiting:
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
c
Person ID: 1
Destination level: 6
Idle: 1
Waiting: 1
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Idle: 1
Waiting: 1
Lift 1 |0|
Lift 2 |0| UP
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |0|
Lift 2 |1| UP
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |0|
Lift 2 |1| UP
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |0|
Lift 2 |1| UP
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 1
Waiting:
Lift 1 |0|
Document Page
Lift 2 |1|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
o
Idle: 2
Waiting:
Lift 1 |0|
Lift 2 |0|
Lift 3 |0|
Choice (a/r/p/c/l/o/x):
x
8
Requirements
Your design must consist of exactly the following set of classes and fields. All fields
must be declared private. You may not add or remove classes or fields. You may add
constructors, functions and procedures. (Copy and paste this into a new project)
public class Building {
private int entrance = 2;
private int bottom = 1;
private int top = 6;
private LinkedList<Lift> lifts = new LinkedList<Lift>();
private LinkedList<Person> people = new LinkedList<Person>();
private String mode;
}
public class Lift {
private int number;
private int bottom;
private int top;
private int level;
private int direction;
private LinkedList<Person> passengers = new
chevron_up_icon
1 out of 15
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]