Я пытаюсь редактировать значения liftobject из LiftObject. java в списке массивов с именем lift. Я пытаюсь использовать setDirection (), чтобы изменить это значение с 0 на 22 (должно быть -1, но я только что тестировал).
LiftObject. java
package system;
import java.io.Serializable;
public class LiftObject implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
int capacity;
int direction;
int currentFloor;
int LiftNum;
int id;
public LiftObject(int capacity, int direction, int currentFloor, int LiftNum){
this.capacity = capacity;
this.direction = direction;
this.currentFloor = currentFloor;
this.LiftNum = LiftNum;
}
public int getCapacity(){return this.capacity;}
public int getDirection(){return this.direction;}
public int getCurrentFloor(){return this.currentFloor;}
public int getLiftNum(){return this.LiftNum;}
public int setCapacity(int capacity){return this.capacity;}
public int setDirection(int direction){return this.direction;}
public int setCurrentFloor(int currentFloor){return this.currentFloor;}
public int setLiftNum(int LiftNum){return this.LiftNum;}
}
Затем основной файл, TestSystem. java
package system;
public class TestSystem {
static int TopFloor = 20;
static int Capacity = 8;
int W_PersCount = 0;
int A_PersCount = 0;
int T_PersCount = 0;
public static ObjectArrayList lift = new ObjectArrayList();
public static ObjectArrayList wPers = new ObjectArrayList();
public static ObjectArrayList tPers = new ObjectArrayList();
public static ObjectArrayList aPers = new ObjectArrayList();
public void DirectLift() {
System.out.println("Direct Lift Start.");
//The lift only changes direction when it hits the top or bottom
int CF =((LiftObject) TestSystem.lift.get(0)).getCurrentFloor();
System.out.println("Floor: ");
System.out.println(CF);
if( CF == 0) {
((LiftObject) TestSystem.lift.get(0)).setDirection(+1);
System.out.println(((LiftObject) TestSystem.lift.get(0)).getDirection());
}else if(CF == TopFloor){
((LiftObject) TestSystem.lift.get(0)).setDirection(-1);
System.out.println(((LiftObject) TestSystem.lift.get(0)).getDirection());
}else {
System.out.println("Continue");
}
}
public void LiftGeneration(int capacity, int direction, int currentFloor, int LiftNum) {
LiftObject obj = new LiftObject(capacity,direction,currentFloor,LiftNum);
obj.capacity = capacity;
obj.direction = direction;
obj.currentFloor = currentFloor;
obj.LiftNum = LiftNum;
lift.add(obj);
System.out.println(((LiftObject) TestSystem.lift.get(0)).getCapacity());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getDirection());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getCurrentFloor());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getLiftNum());
}
public void System() {
//The lift only changes direction when it hits the top or bottom
int CF =((LiftObject) TestSystem.lift.get(0)).getCurrentFloor();
System.out.println("Floor: ");
System.out.println(CF);
System.out.println("Direct Lift Start.");
System.out.println(((LiftObject) TestSystem.lift.get(0)).getCapacity());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getDirection());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getCurrentFloor());
System.out.println(((LiftObject) TestSystem.lift.get(0)).getLiftNum());
((LiftObject)TestSystem.lift.get(0)).setDirection(22);
System.out.println(((LiftObject) TestSystem.lift.get(0)).getDirection());
}
public static void main(String[] args) {
System.out.println("Start.");
TestSystem myObj = new TestSystem(); // Create an object of MyClass
myObj.LiftGeneration(Capacity, 0, 0, 1);
System.out.println("Works here");
myObj.System();
}
Проблема в том, что никаких изменений не происходит, когда я пытаюсь изменить направление с 0 -1 -1014 * Любая помощь будет принята с благодарностью, спасибо.