Question

In: Computer Science

You have been asked to design an elevator system. The functions of an elevator includes moving...

You have been asked to design an elevator system.

The functions of an elevator includes moving up and down, open and close doors, and pick up passengers.

The elevator is supposed to be used in a building having floors numbered from 1 to MaxFloor, where the first floor is the lobby.

There are car call buttons in the car corresponding to each floor.

For every floor except for the top floor and the lobby, there are two hall call buttons for the passengers to call for going up and down.

There is only one down hall call button at the top floor and one up hall call button in the lobby. When the car stops at a floor, the doors are opened and the car lantern indicating the current direction the car is going is illuminated so that the passengers can get to know the current moving direction of the car.

The car moves fast between floors, but it should be able to slow down early enough to stop at a desired floor. In order to certificate system safety, emergency brake will be triggered and the car will be forced to stop under any unsafe conditions.

Follow the process documented above to design the Elevator System.


Questions :

1. Specify the requirements

2. Design a solution

3. Implement the solution with java

4. Test the solution

Solutions

Expert Solution

Requirements:

The elevator is supposed to be used in a building having floors numbered from 1 to MaxFloor, where the first floor is the lobby. There are car(Lift) call buttons in the car corresponding to each floor. For every floor except for the top floor and the lobby, there are two hall call buttons for the passengers to call for going up and down. There is only one down hall call button at the top floor and one up hall call button in the lobby. When the car stops at a floor, the doors are opened and the car lantern indicating the current direction the car is going is illuminated so that the passengers can get to know the current moving direction of the car. The car moves fast between floors, but it should be able to slow down early enough to stop at the desired floor. In order to certificate system safety, emergency brake will be triggered and the car will be forced to stop under any unsafe conditions.

DESIGN:

Based on the above requirements, we have use-cases such as

  • Process Car/Lift Calls: This use case includes several scenarios. These scenarios include that the elevator receives lift/car calls from the passengers, turns on or turns off the light of lift/car call buttons, updates the record of lift/car calls stored in system controlling parts, etc.
  • Process Hall Calls: this use case includes that the elevator receives hall calls from the passengers, turns on or turns off the light of hall call buttons, updates the record of hall calls in the system controlling parts.
  • Move/Stop the Car: The main function of an elevator will include the changing of driving speed, how to make the decision to stop, and driving directions of the car.
  • Indicating Moving Direction: The elevator should have this mechanism to let the passengers know the current moving direction of the car such that the passenger might decide whether to enter the car or not.
  • Indicating Car Position: Similarly, the elevator should let the passengers know whether his/her destination floor is reached so that the passenger may decide to leave the car.
  • Open/Close the Doors: The elevator should be able to open and close the doors for the passengers to get in and out of the car. The functional areas of this use case should also enable the passengers to make door reversals when the doors are closing and the passenger wants to get in the car.
  • Trigger Emergency Brake: There is a safety mechanism within the car to make sure that an unsafe state is not transiently generated.

Based on the use-cases mentioned we have various control classes and control objects to implement the functionalities. The implementation of the system is done in java.

CODE:

public class Elevator {
private float location = 0;
private Direction direction = Direction.UP;
private State state = State.STOPPED;
private Door door = Door.CLOSED;
private Thread processingThread;
private Thread listeningThread;

public class Request {
public long time;
public Integer floor;
public Direction direction;

public Request(long time, Integer floor, Direction direction) {
this.time = time;
this.floor = floor;
this.direction = direction;
}
}

public enum Direction {
UP, DOWN
}

public enum State {
MOVING, STOPPED
}

public enum Door {
OPEN, CLOSED
}

public Comparator<Request> upComparator = new Comparator<Request>() {
public int compare(Request u1, Request u2) {
return u1.floor.compareTo(u2.floor);
}
};

public Comparator<Request> downComparator = upComparator.reversed();

private Queue<Request> upQueue = new PriorityQueue<>(upComparator);
private Queue<Request> currentQueue = upQueue;
private Queue<Request> downQueue = new PriorityQueue<>(downComparator);

public void call(int floor, Direction direction) {
if (direction == Direction.UP) {
if (floor >= location) {
currentQueue.add(new Request(System.currentTimeMillis(), floor,
direction));
} else {
upQueue.add(new Request(System.currentTimeMillis(), floor,
direction));
}
} else {
if (floor <= location) {
currentQueue.add(new Request(System.currentTimeMillis(), floor,
direction));
} else {
downQueue.add(new Request(System.currentTimeMillis(), floor,
direction));
}
}
}

public void go(int floor) {
call(floor, direction);
}

public void process() {
while (true) {
if (!upQueue.isEmpty() && !downQueue.isEmpty()) {
Request r = currentQueue.poll();
if (r != null) {
goToFloor(r.floor);
} else {
preProcessNextQueue();
}
}
}
}

public void goToFloor(int floor) {
state = State.MOVING;
for (float i = location; i <= floor; i = (float) (i + 0.1)) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
location = floor;
door = Door.OPEN;
state = State.STOPPED;
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
door = Door.CLOSED;
}

private void preProcessNextQueue() {
if (getLowestTimeUpQueue() > getLowestTimeDownQueue()) {
this.direction = Direction.UP;
currentQueue = upQueue;
upQueue = new PriorityQueue<>(upComparator);
} else {
this.direction = Direction.DOWN;
currentQueue = downQueue;
downQueue = new PriorityQueue<>(downComparator);
}
}

private long getLowestTimeUpQueue() {
long lowest = Long.MAX_VALUE;
for (Request r : upQueue) {
if (r.time < lowest)
lowest = r.time;
}
return lowest;
}

private long getLowestTimeDownQueue() {
long lowest = Long.MAX_VALUE;
for (Request r : downQueue) {
if (r.time < lowest)
lowest = r.time;
}
return lowest;
}

public class Process implements Runnable {
@Override
public void run() {
process();
}
}

public class Listen implements Runnable {
@Override
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(90000);
while (true) {
Socket socket = serverSocket.accept();
Thread thread = new Thread(new Worker(socket));
thread.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

public class Worker implements Runnable {
private Socket s;

public Worker(Socket s) {
this.s = s;
}

@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(s.getInputStream()));
String line;
while (true) {
if ((line = reader.readLine()) != null) {
String[] tokens = line.split(" ");
if(tokens.length == 3 && tokens[0].equals("call")){
call(Integer.parseInt(tokens[1]), tokens[2].equals("up")?Direction.UP:Direction.DOWN);
}else if(tokens.length == 2 && tokens[0].equals("go")){
go(Integer.parseInt(tokens[1]));
}else{
s.getOutputStream().write("Wrong input".getBytes());
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

public static void main(String[] args) {
Elevator elevator = new Elevator();
elevator.listeningThread = new Thread(elevator.new Listen());
elevator.listeningThread.start();
elevator.processingThread = new Thread(elevator.new Process());
elevator.processingThread.start();
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


Related Solutions

Assume that you have been asked to design an experiment for the marketing department of a...
Assume that you have been asked to design an experiment for the marketing department of a major automotive company. They would like to know what color(s) are most appealing to 18-24 year olds who purchase new trucks. Design an appropriate experiment, and then submit a short (< 3 pages) Technical Memo presenting your proposal. At a minimum, your memo should include: • A clear objective statement for your experiment • Procedure for collecting data • Methodology for analyzing the data...
You have been asked to design a can with a volume of 500cm3 that is shaped...
You have been asked to design a can with a volume of 500cm3 that is shaped like a right circular cylinder. The can will have a closed top. What radius r and height h, in centimeters, would minimize the amount of material needed to construct this can? Enter an exact answer.
Imagine you work for an industrial chemical company and you have been asked to design a...
Imagine you work for an industrial chemical company and you have been asked to design a novel cleaning agent against a group of microorganisms. Select a specific organism representative of the group you chose, gather information about it, and identify the potential "target" within the organism suitable for your cleanser to attack, discussing how your chemical will control the growth of the organism.
You have been asked to design a new stunt for the opening of an ice show...
You have been asked to design a new stunt for the opening of an ice show at Baxter Arena. A small 50 kg skater glides down a ramp and along a short level stretch of ice. The skater then grabs the bottom end of a large 180 kg vertical rod which is free to turn vertically about an axis through its center. The plan is for her to hold onto the 6 meter long rod while it swings her 180°...
As an Electrical Engineer, you have been asked to design a receiver that detects a particular...
As an Electrical Engineer, you have been asked to design a receiver that detects a particular sequence of bits transmitted from a remote transmitter. Your system is a MEALY machine that has an input ‘w’ and an output ‘z’ that produces z=1 when the previous two values of w are 00 or 11 otherwise it should give z=0. Please note that there would be only 3 states. Draw the corresponding state diagram and state table.
You have been asked to design a tunnel in soft ground to be constructed by Tunnel...
You have been asked to design a tunnel in soft ground to be constructed by Tunnel Boring Machine (TBM). Describe how you would set up a finite element model for this type of structure. What are the key features of the model. Discuss the advantages of a 3D model compared to a 2D plane strain model.
You have been asked to design a network (wired, wireless, or a combination) for a home...
You have been asked to design a network (wired, wireless, or a combination) for a home on which construction will start soon. The home is serviced by a cable TV provider and local phone company, and both provide Internet connectivity. It has two levels totaling 250 meters2 (2700 feet2). Five people will live in the home and use three laptop/tablet computers, a desktop computer, a multimedia server, an Internet-connected TV device (for example, TiVo or digital cable DVR), two multifunction...
2. You have been asked to `present on the foundational principles of conditioning program design to...
2. You have been asked to `present on the foundational principles of conditioning program design to a group of dieticians who have studied exercise science in theory, but now seek ideas on how to apply their knowledge in practice. Draft 6-8 key talking points to illustrate scientific exercise programming principles and expand on each of the talking points you identify to clarify their application.
You have been asked by your supervisors at A&L Engineering to design a roller coaster for...
You have been asked by your supervisors at A&L Engineering to design a roller coaster for a new theme park. Because this design is in the initial stages, you have been asked to create a track for the ride. Your coaster should have at least two peaks and two valleys, and launch from an initial height of 75 meters. Each peak and valley should represent a vertical change of at least 20 meters. In your design, you should plan for...
1. As a molecular biologist, you have been asked to design a liposome (artificial cell). The...
1. As a molecular biologist, you have been asked to design a liposome (artificial cell). The purpose of the liposome is to carry drug to the inner linings of the stomach cells, which are cancerous. How would you design the liposome? Most specifically, what should be the biochemical properties of the cell membrane of the liposome? 2. Name and describe three functions of the cell membrane 3. explain and justify the importance of the cell membrane’s fluid mosaic model.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT