Question: I need help figuring out the TODOS in this class public class PeopleSim extends JFrame { private static final int WIDTH = 7 0 0

I need help figuring out the TODOS in this class public class PeopleSim extends JFrame {
private static final int WIDTH =700;
private static final int HEIGHT =700;
private static final int TITLE_HEIGHT =15;
private static final String TITLE = "Zombies";
private static final int NUMBER_PEOPLE =100;
private static final int SLEEP_TIME_PER_PERSON =1; // ms
private static Random rnd = new Random();
private World world;
private int numberOfPeople;
PeopleSim(int numberOfPeople){
if (numberOfPeople >0)
this.numberOfPeople = numberOfPeople;
else
this.numberOfPeople = NUMBER_PEOPLE;
setTitle(TITLE);
setSize(WIDTH, HEIGHT + TITLE_HEIGHT);
world = new World(0,0, WIDTH -1, HEIGHT -1);
setContentPane(world);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
static int randomInt(int min, int max){
return rnd.nextInt(max - min +1)+ min;
}
// TODO Create numberOfPeople alive People at random locations in the world with random destinations
// TODO Create one undead People at the center of the world
void createPeople(){
for (int i =0; i < numberOfPeople; i++){
int x = randomInt(0, WIDTH);
int y = randomInt(0, HEIGHT);
int destX = randomInt(0, WIDTH);
int destY = randomInt(0, HEIGHT);
Location location = new Location(x, y);
Location destination = new Location(destX, destY);
Alive alive = new Alive(location, destination);
world.addPerson(alive);
}
Location undeadLocation = new Location(WIDTH /2, HEIGHT /2);
Undead undead = new Undead(undeadLocation);
world.addPerson(undead);
}
void run(){
while (world.hasPeople()){
world.update();
world.repaint();
try {
Thread.sleep(numberOfPeople * SLEEP_TIME_PER_PERSON);
} catch (InterruptedException ex){
ex.printStackTrace();
}
}
JOptionPane.showMessageDialog(null,"No more people alive; simulation ends now!");
System.exit(0);
}
}
PeopleSim class contains the run method that controls the iterations of the simulation. It extends JFrame and implements the GUI. The run method will call update and repaint methods of World class. The World class extends JPanel and is added to the PeopleSim GUI window.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!