I have an assignment where I am supposed to use classes to build a village population in an array and where every instance in the array is a special class which at the moment only contains a boolean value determining if they are sick or not but it only adds null to the array.
import java.lang.reflect.Array;
import java.util.Random;
public class Start {
public static void main(String[] args) {
Village village = new Village();
}
}
class Village {
final int SIZE = 1000;
Person[] population = new Person[SIZE];
Village() {
for (int i = 0; i < SIZE; i = i + 1) {
Person personen = new Person();
Array.set(population, i, personen);
}
}
static int countSick; {
int sjuka = 0;
for (Person personen: population) {
boolean checker = personen.isSick;
if (checker == true) {
sjuka = sjuka + 1;
}
}
}
}
class Person {
boolean isSick;
final double INIT_SICK_PROB = 0.32;
Person() {
Random rand = new Random();
double checker = rand.nextDouble();
if (checker <= INIT_SICK_PROB) {
isSick = true;
} else {
isSick = false;
}
}
}