我是Java的初学者。通过此代码,我实例化了数组中的十个对象。使用for循环,我试图读取对象中变量的状态,所有这些状态均为“ idle”。尽管如此,当没有设置其状态的对象时,代码仍会增加备用“泵”的数量。
我想念什么吗?
These are the objects, the second value known as "pumpStates" is idle for each object.
这是实例化对象的主要方法以及对它们进行计数的方法。
public class systemMain {
static Scanner userInput = new Scanner(System.in);
private static final pump[] pumps = new pump[10];
public static void main(String[] args) {
for (int index = 0; index < pumps.length; index++) {
pumps[index] = new pump(index, "idle", null, index, index, null);
}
menu();
}
public static void pumpStates() {
int idlePumps = 0;
int standbyPumps = 0;
for (int index = 0; index < pumps.length; index++) {
if (pumps[index].getPumpState().equals("idle")); {
idlePumps++;
}
if (pumps[index].getPumpState().equals("standby")); {
standbyPumps++;
}
}
System.out.println("Idle Pumps: " + idlePumps);
System.out.println("Standby Pumps: " + standbyPumps);
}
谢谢!