src/Location.java
/**
	 * update every single person (movement and collisions)
	 */
update every single person (movement and collisions)
update every single person ( movement and collisions )
public void update() {
		Random rand = new Random();
		day = (int)((System.currentTimeMillis() - currTime) / 400);
		hospital.update();
		for (int i = 0; i < population.size(); i++) {
			Person tempPerson = population.get(i);
			if(tempPerson.getState() == Person.State.SICK || tempPerson.getState() == Person.State.HOSPITALIZE)
				currInfection++;
			boolean hospitalize = tempPerson.checkHospitalize();
			if(hospitalize) {
				if(rand.nextFloat()<=tempPerson.getdeathProb()){
					population.get(i).setDeath();
					population.remove(tempPerson);
					death+=1;
				}
				if(hospital.checkNotFull()) {
					setBedLocation();
					population.remove(tempPerson);
					tempPerson.setX(bedX);
					tempPerson.setY(bedY);
					bedX += maxSize;
					tempPerson.setHospitalTime(System.currentTimeMillis());
					hospital.addPatient(tempPerson);
				}
			}
		}
		for (int i = 0; i < hospital.hospitalMember.size(); i++) {
			Person tempPerson = hospital.hospitalMember.get(i);
			if ((System.currentTimeMillis() - tempPerson.getHospitalTime()) >= (tempPerson.getrecoveryTime()/2.0f))
			{
				population.get(i).setRECOVERY();
				tempPerson.setRECOVERY();
				tempPerson.setX(rand.nextInt(width/4 * 3 - maxSize) + (width / 4));
				tempPerson.setY(rand.nextInt(height - maxSize));
				population.add(tempPerson);
				hospital.removePatient(tempPerson);
			}
		}
		for (int i = 0; i < population.size(); i++) {
			population.get(i).update(xWalls, yWalls, width, height);
			for (int j = 0; j < population.size(); j++)
				if (i != j) {
					Person p1 = population.get(i);
					Person p2 = population.get(j);
					boolean collided = p1.collided(p2);
					if (collided)
					{
						float xv1 = p1.getxVel();
						float yv1 = p1.getyVel();
						float speed1=(float)Math.sqrt(xv1*xv1+yv1*yv1);
						float xv2 = p2.getxVel();
						float yv2 = p2.getyVel();
						float speed2=(float)Math.sqrt(xv2*xv2+yv2*yv2);
						p1.setxVel((float)speed1*xv2/(float)Math.sqrt(xv2*xv2+yv2*yv2));
						p1.setyVel((float)speed1*yv2/(float)Math.sqrt(xv2*xv2+yv2*yv2));
						p2.setxVel((float)speed2*xv1/(float)Math.sqrt(xv1*xv1+yv1*yv1));
						p2.setyVel((float)speed2*yv1/(float)Math.sqrt(xv1*xv1+yv1*yv1));
					}
				}
		}
		infection = currInfection;
		currInfection = 0;
	}
public void update ( ) { Random rand = new Random ( ) ; day = ( int ) ( ( System . currentTimeMillis ( ) - currTime ) / 400 ) ; hospital . update ( ) ; for ( int i = 0 ; i < population . size ( ) ; i ++ ) { Person tempPerson = population . get ( i ) ; if ( tempPerson . getState ( ) == Person . State . SICK || tempPerson . getState ( ) == Person . State . HOSPITALIZE ) currInfection ++ ; boolean hospitalize = tempPerson . checkHospitalize ( ) ; if ( hospitalize ) { if ( rand . nextFloat ( ) <= tempPerson . getdeathProb ( ) ) { population . get ( i ) . setDeath ( ) ; population . remove ( tempPerson ) ; death += 1 ; } if ( hospital . checkNotFull ( ) ) { setBedLocation ( ) ; population . remove ( tempPerson ) ; tempPerson . setX ( bedX ) ; tempPerson . setY ( bedY ) ; bedX += maxSize ; tempPerson . setHospitalTime ( System . currentTimeMillis ( ) ) ; hospital . addPatient ( tempPerson ) ; } } } for ( int i = 0 ; i < hospital . hospitalMember . size ( ) ; i ++ ) { Person tempPerson = hospital . hospitalMember . get ( i ) ; if ( ( System . currentTimeMillis ( ) - tempPerson . getHospitalTime ( ) ) >= ( tempPerson . getrecoveryTime ( ) / 2.0f ) ) { population . get ( i ) . setRECOVERY ( ) ; tempPerson . setRECOVERY ( ) ; tempPerson . setX ( rand . nextInt ( width / 4 * 3 - maxSize ) + ( width / 4 ) ) ; tempPerson . setY ( rand . nextInt ( height - maxSize ) ) ; population . add ( tempPerson ) ; hospital . removePatient ( tempPerson ) ; } } for ( int i = 0 ; i < population . size ( ) ; i ++ ) { population . get ( i ) . update ( xWalls , yWalls , width , height ) ; for ( int j = 0 ; j < population . size ( ) ; j ++ ) if ( i != j ) { Person p1 = population . get ( i ) ; Person p2 = population . get ( j ) ; boolean collided = p1 . collided ( p2 ) ; if ( collided ) { float xv1 = p1 . getxVel ( ) ; float yv1 = p1 . getyVel ( ) ; float speed1 = ( float ) Math . sqrt ( xv1 * xv1 + yv1 * yv1 ) ; float xv2 = p2 . getxVel ( ) ; float yv2 = p2 . getyVel ( ) ; float speed2 = ( float ) Math . sqrt ( xv2 * xv2 + yv2 * yv2 ) ; p1 . setxVel ( ( float ) speed1 * xv2 / ( float ) Math . sqrt ( xv2 * xv2 + yv2 * yv2 ) ) ; p1 . setyVel ( ( float ) speed1 * yv2 / ( float ) Math . sqrt ( xv2 * xv2 + yv2 * yv2 ) ) ; p2 . setxVel ( ( float ) speed2 * xv1 / ( float ) Math . sqrt ( xv1 * xv1 + yv1 * yv1 ) ) ; p2 . setyVel ( ( float ) speed2 * yv1 / ( float ) Math . sqrt ( xv1 * xv1 + yv1 * yv1 ) ) ; } } } infection = currInfection ; currInfection = 0 ; }
update every single person (movement and collisions)
update every single person ( movement and collisions )
//Update Hostpital Conditions //Check every person whether they need to get into hospital //Whether they will die today // System.out.println("Current Death:" +death); //Update every person in the hospital