1 For the questions below consider a class called BuildingTh

1

For the questions below, consider a class called Building.This class consists of a number of floors

(numberOfFloors) for the Building, a current floor for the elevator (current), a requested floor of a person

waiting for the elevator (requestedFloor), and methods for constructing the building object, for moving

the elevator one floor up, for moving the elevator one floor down, for requesting the elevator and for starting the

elevator going. Assume that requestedFloor will be set to 0 if there are currently no requests being made (or

the last request has already

been fulfilled).

[1 Write Constructor For This Class?

-

2]

What visibility modifiers would you use for the methods that move the elevator up one floor, move the

elevator down one floor, that request the elevator, and that start the elevator moving?

Solution

1.

public Building(int numFloors)

{

numberOfFloors = numFloors;

current = 1;

requestedFloor = 0;

}

2.

public void requestTheElevator(int floor)

{

if (floor < 1 || floor > numberOfFloors)

{

System.out.println(\"The requested floor \" + floor + \" is not within this building! \");

requestedFloor = 0;

}

Else

{

requestedFloor = floor;

startMoving( );

}

}

1 For the questions below, consider a class called Building.This class consists of a number of floors (numberOfFloors) for the Building, a current floor for the
1 For the questions below, consider a class called Building.This class consists of a number of floors (numberOfFloors) for the Building, a current floor for the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site