I'm trying to create a Java program that generates an amount of seats taken in an airplane. So far, I have been able to do this, but my problem is every time I run the client the numbers generated are different. I need them to be the same every time...
I'm not sure what I'm doing wrong, can anybody help me?
import java.util.Random;
import java.util.Arrays;
public class Airplane {
public static Random randomNumbers = new Random();
public static int[] oSeatLeft = new int[10];
public static int[] mSeatLeft = new int[10];
public static int[] wSeatLeft = new int[10];
public static int oSeat = 0;
public static int mSeat = 0;
public static int wSeat = 0;
public static final int sCheck = 0;
public void genWSeats() {
int randSeatFill = 0;
if (wSeat == 0) {
for (int counter = 0; counter < wSeatLeft.length; counter++) {
randSeatFill = randomNumbers.nextInt(2);
if (randSeatFill == 1) {
wSeatLeft[counter] = 1;
}
}
if (wSeat == 0) {
wSeat++;
}
}
}
public int[] getWSeats() {
System.out.println(java.util.Arrays.toString(wSeatLeft));
return wSeatLeft;
}
}
The purpose of static int wSeat is supposed to be a checker. If wSeat is greater than zero, then it should not randomly generate numbers for the array. Not sure exactly what is going wrong here....