Servlet+ajax implementation of analog elevator scheduling

Source: Internet
Author: User

Demand generation:

  Junior next semester every day in the school of the same teaching building, four times a day to wait for the elevator, a second-class elevator bored, think of the elevator running logic how to use the program to express it?

Problem Description:

  The university's building has 21 floors, but in the page to draw 21 layers is a bit dense, so only painted 9 layers;

At the same time there are three elevators waiting for dispatch;

Buttons are divided into floor buttons and elevator buttons, elevator buttons have floor numbers and door buttons;

Requirements for operation:

1. When the elevator is idle, the button in the elevator is clicked, the corresponding button is lit, and the closing key needs to be automatically run to the nearest floor;

2. The elevator is running, the elevator button is clicked, if it is closer to the elevator, you need to automatically change the elevator destination floor for the newly added request floor, or the elevator will arrive at the original floor;

3. The elevator in the opposite state of the elevator button will not be responsive, such as the elevator from the four floor up, 1, 2, 3 floor buttons can not be clicked;

4. Floor button request because three elevators share button request, so should design a reasonable scheduling choice;

① the most preferential choice such elevator: is going to this floor elevator, such as 5 floor up button was clicked, Elevator B to from 3 floor to 9 floor, then preferential choice Elevator B, and will first stop 5 floor;

② second choice such elevator: idle state elevator, if there is no ① in accordance with the conditions of the elevator, then randomly select an idle state elevator (here can be optimized, select the nearest elevator) run to the current floor pick-up;

③ If there are no elevators with the above two conditions, then keep the request state, until one of the above two conditions, such as the 1 floor of the upward request, but the elevator ABC is from the 2 floor up, then select the first to complete the task to stop the elevator to the 1 floor pick-up.

5. Elevator to a certain level, the elevator lights on the button is extinguished, there are two types of floor buttons:

① current elevator reached this floor there is no next floor of the target, change the status of idle, up and down buttons are off (this is because the 4-② in the request, but when the elevator running up from below, the off should be down button);

② The current elevator has the next level of target to continue running, only the floor buttons that are the same as the current direction of operation are extinguished.

Interface:

  

Package Structure:

1.PO Layer:

Futurefloor as the entity class, use five TreeSet save button request data (because TreeSet order, unique), these five treeset respectively save, floor rise request, floor drop request, three elevator inside button request;

Futurefloorfactory, the factory class of the entity class;

2.service Layer

Service: Encapsulate some methods;

3.servlet:

In order, respectively:

The response triggered when the elevator stops at the floor;

The response triggered when the elevator starts running;

The response triggered when the Close button is clicked in the elevator;

Set the coded filter;

In-elevator button response;

Floor button response;

Return the current status of the elevator to the front page;

Defects:

In fact, save the elevator state only in the front-end save, and then pass on it, the background to save the need to change the state of each operation, easy to cause flaws, and no page save the real-time;

Source:

Https://files.cnblogs.com/files/liumaowu/elevator.zip

    

Servlet+ajax implementation of analog elevator scheduling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.