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 ;
private static final int HEIGHT ;
private static final int TITLEHEIGHT ;
private static final String TITLE "Zombies";
private static final int NUMBERPEOPLE ;
private static final int SLEEPTIMEPERPERSON ; ms
private static Random rnd new Random;
private World world;
private int numberOfPeople;
PeopleSimint numberOfPeople
if numberOfPeople
this.numberOfPeople numberOfPeople;
else
this.numberOfPeople NUMBERPEOPLE;
setTitleTITLE;
setSizeWIDTH HEIGHT TITLEHEIGHT;
world new World WIDTH HEIGHT ;
setContentPaneworld;
setDefaultCloseOperationJFrameEXITONCLOSE;
setVisibletrue;
static int randomIntint min, int max
return rndnextIntmax min 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 ; i numberOfPeople; i
int x randomInt WIDTH;
int y randomInt HEIGHT;
int destX randomInt WIDTH;
int destY randomInt HEIGHT;
Location location new Locationx y;
Location destination new LocationdestX destY;
Alive alive new Alivelocation destination;
world.addPersonalive;
Location undeadLocation new LocationWIDTH HEIGHT ;
Undead undead new UndeadundeadLocation;
world.addPersonundead;
void run
while worldhasPeople
world.update;
world.repaint;
try
Thread.sleepnumberOfPeople SLEEPTIMEPERPERSON;
catch InterruptedException ex
exprintStackTrace;
JOptionPane.showMessageDialognullNo more people alive; simulation ends now!";
System.exit;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
