Skip to content
15 changes: 15 additions & 0 deletions src/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ public int getNumberOfFloors() {
return this.numberOfFloors;
}

/**
* Author: Elijah Smith
* Issue #67 pushedUp accessor
*/
public boolean[] getPushedUpArray() {
return this.pushedUp;
}

/**
* Author: Elijah Smith
* Issue #67 pushedDown accessor
*/
public boolean[] getPushedDownArray() {
return this.pushedDown;
}
public void stop() {
this.stopped = true;
}
Expand Down
32 changes: 29 additions & 3 deletions src/Passenger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,45 @@ public class Passenger
{
private int startFloor;
private int destinationFloor;

public Passenger(int startFloor, int destinationFloor)
private boolean waiting;
Elevator elev;
public Passenger(Elevator elev, int startFloor, int destinationFloor)
{
this.elev = elev;
this.startFloor = startFloor;
this.destinationFloor = destinationFloor;
this.waiting = false;
}

public Passenger(int destinationFloor)
public Passenger(Elevator elev, int destinationFloor)
{
this.elev = elev;
this.waiting = false;
this.startFloor = 1;
this.destinationFloor = destinationFloor;
}

public void next()
{
if(!this.waiting)
{
if(this.destinationFloor > elev.getCurrentFloor())
{
elev.pushUp(this.startFloor);
}
else
{
elev.pushDown(this.startFloor);
}
this.waiting = true;
}
}

public boolean getWaiting()
{
return this.waiting;
}

public int getStartFloor()
{
return this.startFloor;
Expand Down
43 changes: 33 additions & 10 deletions tests/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ public void testCurrentFloor() {
int currentFloor = 60;
int totalFloors = 600;
Elevator elevator = new Elevator(currentFloor, totalFloors);

assertEquals(60, elevator.getCurrentFloor());
}

/**
* Author: Elijah Smith
*/
@Test
public void testElevatorConstructor1() {
Elevator elev = new Elevator(100);
Expand Down Expand Up @@ -105,21 +104,45 @@ public void testPushTrue2()

}

@Test
public void testPassengerNext1()
{
Elevator elev = new Elevator(1, 10);
Passenger pass = new Passenger(elev, 7);

pass.next();

assertEquals(true, elev.pushTrue());
}

public void testGetPushedUpArray() {
Elevator elev = new Elevator(100);
elev.pushUp(3);
elev.pushDown(4);

boolean[] goingUp = elev.getPushedUpArray();
boolean[] goingDown = elev.getPushedDownArray();

boolean up = goingUp[3];
boolean down = goingDown[4];

assertEquals(true, up);
assertEquals(true, down);
}

/**
* Author: Elijah Smith

*/
@Test
public void testPassengerConstructor1()
{
Passenger pass = new Passenger(3, 10);

assertEquals(3, pass.getStartFloor());
assertEquals(10, pass.getDestinationFloor());

}

@Test
public void testPassengerConstructor2()
{
Passenger pass = new Passenger(50);

assertEquals(1, pass.getStartFloor());
assertEquals(50, pass.getDestinationFloor());
}
}