Hello Guys,
I am writing an elevator problem and am stuck at the movement of the elevator and also stopping the elevator. The elevator is suppose to state the current floor is starting and the number of passengers that are in the elevator.
I am able to let it go up one floor and finding it difficult going to the highest floor and also for the elevator to go down.
Here is my code:
public class Elevator {
private static int Level = 7;
private static int Passengers = 10;
static int cPassengers = 3;
static int cfloor = 3;
public static void main(String[] args)
{
System.out.println("Currently " + cPassengers + " passenger on board\n" + "Current floor " + cfloor);
System.out.println("................................................................................");
Elevator move = new Elevator();
move.Stop();
move.boardPassenger(cfloor);
}
public void moveUp()
{
cfloor++;
}
public void moveDown()
{
cfloor--;
}
public void boardPassenger(int floor)
{
cfloor = floor;
cPassengers--;
System.out.println("Currently " + --cPassengers + " on borad\n" + "Current floor: " + cfloor);
}
//Elevator stopping at a specfic floor
public void Stop()
{
cfloor++;
System.out.println("Stopping at floor: " + cfloor);
}
}
The requirement is for the elevator to go up and down and also to load and unload passengers.
Thanks in advance for your reply.