Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4: [20 marks] Simulate the movement of an elevator (filename: Elevator.java ) Design an algorithm and then write a program called Elevator, which models

Problem 4: [20 marks] Simulate the movement of an elevator (filename: Elevator.java)

Design an algorithm and then write a program called Elevator, which models a simplified elevator.

  1. The elevator operates in a building with 9 floors. The labelling of the floors begins at 1.
  2. The user will request a floor by typing in an integer in the appropriate range. The elevator

you are modelling needs to move to the requested floor, displaying floor numbers and a

picture of an up/down arrow as it goes.

  1. The program should continue moving to new floors and prompting for a floor selection until the user enters a sentinel value of 0 instead of a floor number. When the sentinel value is entered, the program should exit.
  2. If the entered floor number is not valid, the user should be warned, and the user is asked to enter a floor number again.

A sample runs is given below:

o-------o

| 1 |

o-------o

The elevator is at Floor 1 now

Enter a floor number between 1 and 9, or enter 0 to quit: 5

The elevator is moving up from Floor 1 to 5

o-------o /\

| 5 | //\\

o-------o // \\

o-------o /\

| 4 | //\\

o-------o // \\

o-------o /\

| 3 | //\\

o-------o // \\

o-------o /\

| 2 | //\\

o-------o // \\

o-------o /\

| 1 | //\\

o-------o // \\

The elevator is at Floor 5 now

Enter a floor number between 1 and 9, or enter 0 to quit: 12

Invalid floor number. Try again.

Enter a floor number between 1 and 9, or enter 0 to quit: 3

The elevator is moving down from Floor 5 to 3

o-------o \\ //

| 5 | \\ //

o-------o \/

o-------o \\ //

| 4 | \\ //

o-------o \/

o-------o \\ //

| 3 | \\ //

o-------o \/

The elevator is at Floor 3 now

Enter a floor number between 1 and 9, or enter 0 to quit: 0

Thank you for using the elevator program. Goodbye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

8. Describe the main retirement benefits.

Answered: 1 week ago