Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 2 review Fall2005: Tweak the Politics

Post questions, comments, answers, comments on answers, etc. here.
(Return to Midterm Exam 2 Review Fall2005)


On the practice test...the first question about UML class diagrams... I had A.) building and Person B.)NO C.)Building D.)Weekly Pay / Employee ID / Name / Address E.) Hourly Employee & Salaried Employee, HOWEVER I WAS NOT SURE IF 'PERSON' ALSO BELONGS IN THIS ANSWER...I know Employee, which contains the instance fire() inherits everything from 'PERSON' but does person also know everything in 'EMPLOYEE' ?? -Tannis Betz

Red people that turn blue wouldn't affect blue people at all would they? why would you want to put them in the middle of the blue zone?

For the code to get people to stay put for 5 generations I got:


//How a PoliticalAgent acts
public void act()
{
this.stuckness–;
stuckness = 5;

// What are the number of blues and red near me?
int numBlue = countInRange(30,blueParty);
int numRed = countInRange(30,redParty);
/System.out.println("I am "+politics+" and near me are red:"
+numRed+" and blue:"+numBlue);/
if (politics==Color.red){
// If I'm red, and there are more blue than red near me, convert
if ((numBlue >numRed) & (this.stuckness = 0)){
setPolitics(Color.blue);}
stuckness = 5;
}
if (politics==Color.blue){
// If I'm blue, and there are more red than blue near me, convert
if ((numRed numBlue) & (this.stuckness = 0)) {
setPolitics(Color.red);}
stuckness = 5;
}

// Run the normal act() – wander aimlessly
super.act();
// But don't let them wander too far!
// Let them mix only in the middle
if (politics==Color.red) {
if (this.getXPos() 400) { // Did I go too far right?
this.moveTo(200,this.getYPos());}
}
if (politics==Color.blue) {
if (this.getXPos() 200) { // Did I go too far left?
this.moveTo(400,this.getYPos());}
}

}

whaddya think?Kyle REMOVED

No, Tannis – Person wouldn't also inherit from Employee. Kyle, I wouldn't say stuckness– and on the next line stuckness=5 – wouldn't be very effective, eh? Mark Guzdial

Hint: Do pay attention to this problem. Mark Guzdial

int stuckness = 5;

 /**
   * How a PoliticalAgent acts
   **/
  public void act()
  {
    this.stuckness--;
    
    int numBlue = countInRange(30,blueParty);
    int numRed = countInRange(30,redParty);
    /*System.out.println("I am "+politics+" and near me are red:"
                         +numRed+" and blue:"+numBlue);*/
    if (politics==Color.red){
      // If I'm red, and there are more blue than red near me, convert
      if ((numBlue > numRed) && (this.stuckness <= 0)){
        setPolitics(Color.blue);
        this.stuckness = 5;
      }
    }
    if (politics==Color.blue){
      // If I'm blue, and there are more red than blue near me, convert
      if ((numRed > numBlue) && (this.stuckness <= 0)) {
      setPolitics(Color.red);
      this.stuckness = 5;
      this.moveTo(500,this.getYPos());  
     }
    }

    // Run the normal act() -- wander aimlessly
    super.act();
    
    // But don't let them wander too far!
    // Let them mix only in the middle
    if (politics==Color.red) {
      if (this.getXPos() > 400) { // Did I go too far right?
        this.moveTo(200,this.getYPos());}
    }
     if (politics==Color.blue) {
      if (this.getXPos() < 200) { // Did I go too far left?
        this.moveTo(400,this.getYPos());}
     }
   }





Link to this Page