Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to do this java coding?

+1 vote
asked Mar 15 by Iqbal Syazwan Sharil (130 points)

Write a class program based on the information given below. This class will simulate the operation of an elevator. The elevator can travel between 1st and 15th floors of the building it is situated in.

Class Name:

  • Elevator

Attributes:    

  • private int currentFloor;
  • private static final int MAXFLOOR = 15;

ONE Constructor:

  • to set the value of currentFloor to 1. This method does not have any parameters.

ONE Member method:

  • void request (int newFloor)

 -This method will be used to alter the position of the elevator. This method consists of an if-else statement having three parts:

If an incorrect floor number (i.e. newFloor) is given, no action is taken;

if a floor above  the current position is selected, the elevator moves up;

and if a floor below  the current position is selected, the elevator moves down.

For the movement up and down, the method can use while loop to update the position one floor at a time and report the elevator’s movement using System.out.println().

For example, if an object of Elevator calls the request method as below:

<object>.request(6);

<object>.request(3);

then, the following output will be displayed for the above call:

Starting at floor 1

     Going up -  now at floor 2

     Going up -  now at floor 3

     Going up -  now at floor 4

     Going up -  now at floor 5

     Going up -  now at floor 6

Stopping at floor 6

Starting at floor 6

     Going down -  now at floor 5

     Going down -  now at floor 4

     Going down -  now at floor 3

Stopping at floor 3

1 Answer

0 votes
answered Mar 18 by Peter Minarik (22,320 points)
This looks like a homework assignment of some sort.

The best course of action is that you give your best try to solve it. If you get stuck on something, you can share your code and ask specific questions.

Good luck!
commented Mar 18 by KKN (1,020 points)
Why the dislike? He has a point :P
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...