Directions

A driver class/program and a Elevator.java class is required to make the program compile and run.

Elevator Control

Write a program that mimics the operations of the inside of an elevator. More specifically, the program simulates what happens when the user chooses to go to a particular floor, and it simulates what happens when the user pulls the elevator's fire alarm. Assume the elevator is in a high-rise building that has floors numbered 1 through 100.

Your driver class should call the Elevator class file and implements the requirements above. Refer to the sample output below to see what the prompts and output should look like.Within your driver class, use a loop that continues until the user enters "q" for quit. See the sample session for details .As you implement your solution, you should find that the selectFloor and fireAlarm methods contain some repeated coding logic. To avoid unnecessary redundancies in your code, have those methods call an appropriate helper method. Use a switch statement to handle the different choices for user input. (S-select floor, F-fire alarm, Q-quit). There should also be some coding to recognize which floor the elevator is currently on.

Elevator.java Within your Elevator class, include these methods:

  • selectFloor - This method prompts the user for a floor selection and then performs input validation for the floor selection. If the floor selection is inappropriate (less than 1, greater than 100), then the method prints an error message. If the floor selection is OK, the method simulates going to that floor. See the sample session below for the format of the simulation message.
  • fireAlarm - This method prints a "danger" message and then simulates going to the first floor. Note that Im assuming this is a high tech fire alarm that is programmed to force the elevator to go to the first floor! See the sample session below for the format of the "danger" message.

Sample Session: (output is NOT to be centered). See image

Optional extension: Some hotels cater to superstitious people by omitting the 13th floor. Modify your program so that there is no 13th floor.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.