Привет, я пытаюсь изменить значения объектов в моем массиве, таких как State, с "idle" на "ready". Но когда я запускаю свой код, он изначально печатает новое значение, но затем, когда я пытаюсь снова распечатать массив, он возвращается к исходным значениям? вот часть кода, спасибо :)
public class PumpSystem {
private Pumps station[];
Scanner stdin = new Scanner(System.in);
Attendant attendant = new Attendant();
public PumpSystem() {
station = new Pumps[10];
station[0] = new Pumps("P101", "Idle", "Default", 0.0, 0.0, 0.0);
station[1] = new Pumps("P102", "Idle", "Default", 0.0, 0.0, 0.0);
station[2] = new Pumps("P103", "Idle", "Default", 0.0, 0.0, 0.0);
station[3] = new Pumps("P104", "Idle", "Default", 0.0, 0.0, 0.0);
station[4] = new Pumps("P105", "Idle", "Default", 0.0, 0.0, 0.0);
station[5] = new Pumps("P201", "Idle", "Default", 0.0, 0.0, 0.0);
station[6] = new Pumps("P202", "Idle", "Default", 0.0, 0.0, 0.0);
station[7] = new Pumps("P203", "Idle", "Default", 0.0, 0.0, 0.0);
station[8] = new Pumps("P204", "Idle", "Default", 0.0, 0.0, 0.0);
station[9] = new Pumps("P205", "Idle", "Default", 0.0, 0.0, 0.0);
}
//************** Print-Stations ***********************
public void printStations() {
for (int i = 0; i < station.length; i++) {
System.out.println(" ID: " + station[i].getPumpID() + " --> " + " State: " + station[i].getState());
}
}
//*********************** Switch statement for Statues change ************************************
public void updateModeSelect() {
boolean endLoop = false;
while (!endLoop) {
menu();
int option = stdin.nextInt();
String wait = stdin.nextLine();
switch (option) {
case 0:
System.out.println(" **** Enter new State **** \n");
station[0].setState(stdin.nextLine() + "\n");
System.out.println("Station: P101 State changed to: " + station[0].getState());
attendant.attendantControls();
case 1:
, и я получаю следующий результат:
**** Enter new State ****
Ready <-- user input
Station: P101 State changed to: Ready
*** Logged in as Attendant ***
(1) *** Stations ***
(2) *** Change Pump State ***
(3) *** back to Main Menu ***
(4) *** Shut Down ***
так что он работает, но затем я распечатываю свой массив и его обратно в режим ожидания? это мой класс Pump
public class Pumps {
private String pumpID;
private String state;
private String fuelType;
private double total;
private double pumpOutPut;
private double pumpInTake;
//Constructors
public Pumps ( String pumpID, String state, String fuelType, double total ,
double pumpOutPut, double pumpInTake){
this.pumpID = pumpID;
this.state = state;
this.fuelType = fuelType;
this.total = total;
this.pumpOutPut = pumpOutPut;
this.pumpInTake = pumpInTake;
}
public String getPumpID() {
return pumpID;
}
public void setPumpID(String newPumpID) {
pumpID = newPumpID;
}
//*************MODE*********************
public void setState(String newState) {
state = newState;
}
public String getState() {
return state;
}
//*************FUEL-TYPE*********************
public void setFuelType(String newFuelType) {
fuelType = newFuelType;
}
public String getFuelType() {
return fuelType;
}
//*************PUMP-IN-TAKE*********************
public void setPumpInTake(double newPumpInTake) {
pumpInTake = newPumpInTake;
}
//**************PUMP-OUT-PUT********************
public void setPumpOutPut(double newPumpOutPut) {
pumpOutPut = newPumpOutPut;
}
//*************TOTAL*********************
public void setTotal(double newTotal) {
total = newTotal;
}
@Override
public String toString() {
return pumpID +state + fuelType + total + pumpInTake + pumpOutPut;
}
//**********************************
}
это то, что дежурный делает с serveantControls ()
import java.util.Scanner;
public class Attendant {
public void attendantControls(){
Scanner stdin = new Scanner(System.in);
Main main = new Main();
boolean endLoop = false;
Manager manager = new Manager();
PumpSystem pumpSystem = new PumpSystem();
while (!endLoop) {
menu();
int selection = stdin.nextInt();
switch (selection) {
case 1:
System.out.println("*** Stations *** ");
pumpSystem.printStations();
System.out.println("*************************************************");
break;
case 2:
System.out.println("*** Pump State Managment ***");
pumpSystem.updateModeSelect();
System.out.println("*************************************************");
System.out.println("*************************************************");
break;
case 3:
System.out.println("*** Main Menu ***");
endLoop = true;
default:
System.out.println("Invalid Input - Please Select Options 1-3");
break;
}
}
}
private void menu() {
System.out.println(" \n*** Logged in as Attendant *** ");
System.out.println(" (1) *** Stations ***");
System.out.println(" (2) *** Change Pump State *** ");
System.out.println(" (3) *** back to Main Menu *** ");
System.out.println(" (4) *** Shut Down *** ");
}
}