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

Questions on HW8-Sp2005

Want some help dealing with American Emigration?

ASK HERE!



The instructions say that when crossing the atlantic, the people should move 100 steps per timestep for three timesteps. Isn't 100 way too high? Shouldn't it be more like 33 or 34 since the Atlantic is only 100 wide?

Student36

Hmm, good point! I'll go make it 33. Thanks! Mark Guzdial

I get this error when I try to compile WDSimulation from simulation-pkg-v1.2.zip
Uploaded Image: error.JPG


i'm having trouble with getDistance in Agent.java as well.

Install SimpleTurtle from that .zip, too. We added new capabilities in SimpleTurtle to turnToFace and getDistance. I'll upload mine here, in case I put the wrong one in that .zip. The setAutoRepaint should just work. I'd open World.java and let it get recompiled, too. Mark Guzdial


When I compile my Immigrant.java class, I get this -

File: C:\cs1316\java-source\Immigrant.java  [line: 9]
Error: cannot resolve symbol
symbol  : constructor Agent ()
location: class Agent


and that highlights this line -

public class Immigrant extends Agent {


What is wrong?

Remember to copy in the constructors from DeerAgent or WolfAgent or PoliticalAgent or PersonAgent, and turn the classname to "Immigrant". Those constructors are constructed to work with Agent and Turtle, and will call init() for you to do initialization. Mark Guzdial


I've tried copying everything but it won't work!


I just added an EXTRA CREDIT OPTION to Homework 8 – please take a look and ask questions here. Mark Guzdial

It looks like the last SimpleTurtle.java I uploaded may have been missing getDistance (sigh!) – please try this one. SimpleTurtle.java Mark Guzdial

trying to compile the new simpleTurtle, got this error:

File: C:\Documents and Settings\Administrator\My Documents\cs1316\java source\java source from 2-3-05\java-source\SimpleTurtle.java [line: 528]
Error: cannot resolve symbol
symbol : method getGraphics ()
location: interface ModelDisplay


that method (getGraphics) is in simplePicture so i re-complied that but no luck.


Whenever I do 150 people my computer runs out of memory... or stumbles along the way. =/

i don't see "turnToFace" in any of the simpleTurle files.

getGraphics should also be in World.java – that's the one that it's trying to reach. Try to recompile that, too. If you're running out of memory, use the techniques I showed in class Monday for running outside of DrJava. Mark Guzdial

Very weird! Yes, you're right, the one that's uploaded is WRONG (it's missing important stuff), but it's right on my disk! I'm zipping it and attaching it here. Try this one, please! SimpleTurtle.java.zip Mark Guzdial



How do you create the turtles in random locations.. but within a certain part of the world?
Two choices:
  1. There is a constructor for the agents that takes an X,Y – you could explicitly set it.
  2. Or, in your init() method, move them to a random place.
Mark Guzdial

Are we supposed to start making the simulation by making the simulation first or the agentnode?
You'll probably have to create an instance of your Simulation class first – that's how we've run all the simulations we've done so-far. Mark Guzdial

anyone: can i have a hint on how to make an observation over the course of 3 time steps. like when where suppose to see if there are 5 europeans within 20 pixels for 3 time steps.
Right – that's a little tricky. You're going to need an array or linked list – something to store the "last 3" time steps. Store in it the number of Europeans near you. (Maybe this is a Queue?) Mark Guzdial

also...How do you stop making the turtles follow the "super" of just wandering aimlessly once they decided to immigrate
Don't call super.act(). Do your own "wandering aimlessly" but within the bounds that you want. Mark Guzdial

If 10% of the turtles experience crop failure each timestep, doesn't that mean that all of them will in America by little more than half the simulation? Don't we want people to still be in Europe?
It's not obvious from first glance, but yup, that's what I'm seeing in the students' simulations I'm seeing. Sounds like that's a variable to explore changing in your other scenarios! Mark Guzdial

I have tried every version of simpleTurtle that you have uploaded. I keep getting the same error:
Error: cannot resolve symbol
symbol : method getGraphics ()
location: interface ModelDisplay

When I checked ModelDisplay, there is no such thing as getGraphics. I see no getGraphics in world.java either. I am sure I am missing something. So can you please tell me what that is.
You need the World.java file that is in the mark-java-sources-v2.zip that is on the Syllabus page. Patricia had the same problem, and that's where we found the right World.java file. Mark Guzdial

How do you save each frame as a jpeg to make a movie? I know what to do with the frames, but how do you make the frames?
mySim.openFrames("C:/temp/") will work – openFrames will create a FrameSequence, and write the frames to it. Mark Guzdial

How are folks doing with HW8? Mark Guzdial



Error: cannot resolve symbol
symbol : method openFrames (java.lang.String)
location: class ImmigrationSimulation

Does ImmigrationSimulation extend Simulation? It's in Simulation (see below). Mark Guzdial
  /** 
   * Open a frame sequence at the given directory
   * @param dir String where the directory is
   **/
  public void openFrames(String dir){
    frames = new FrameSequence(dir);
  }



That's funny... in my simulation that doesn't exist.

I downloaded a new Simulation from your java sources v.2 but now Simulation won't compile.

Now I get this error message.

Error: non-static method openFrames(java.lang.String) cannot be referenced from a static context


and

Error: cannot resolve symbol
symbol  : variable frames 
location: class Simulation

I need to see your code. Where are you calling openFrames()? It sounds like it's the wrong place. Mark Guzdial

Ok. I can't even get the DiseaseSimulation to run because my Agent class won't compile. I keep getting the following errors:
3 errors found:
File: C:\Documents and Settings\Ang\Desktop\Java Stuff\java-source-11Feb\java-source\Agent.java [line: 129]
Error: cannot resolve symbol
symbol : method getDistance (int,int)
location: class Agent
File: C:\Documents and Settings\Ang\Desktop\Java Stuff\java-source-11Feb\java-source\Agent.java [line: 161]
Error: cannot resolve symbol
symbol : method getDistance (int,int)
location: class Agent
File: C:\Documents and Settings\Ang\Desktop\Java Stuff\java-source-11Feb\java-source\Simulation.java [line: 57]
Error: cannot resolve symbol
symbol : method setAutoRepaint (boolean)
location: class World

How can I fix this?
You don't have the latest SimpleTurtle.java and World.java. Mark Guzdial

when i start the simulation all the turtles are in one place so my code automatically moves most of them to live in america cause they are all within 20 steps on one another... is there any way to make them scattered while in the same general area?
Sure! In your init() method, moveTo random values of X and Y. Mark Guzdial

i guess you use the random number generator?
Let's discuss it in class today Mark Guzdial

how do you use it?

Integer hi = new Integer;
hi.randNumGen.nextInt(10);

it's not working.

or hi = randNumGen.nextInt(100);
Neither. Random hi = new Random(); hi.nextInt(10); . Mark Guzdial

This is way too hard!


I've updated, saved, recompiled so that Prof.Guzdial's diseaseSimulation should work, but I'm encountering this error:
java.lang.NoSuchMethodError: World.setAutoRepaint(Z)V
  at ImmigrationSimulation.setUp(ImmigrationSimulation.java:23)
  at Simulation.run(Simulation.java:88)
  at Simulation.run(Simulation.java:117)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source) 

and this is what is in the world.java file:
/**
   * Method to set the automatically repaint flag
   * @param value if true will auto repaint 
   */
  public void setAutoRepaint(boolean value) 
  { 
    autoRepaint = value; 
  } 

and this is what's in my ImmigrationSimulation:
 public void setUp(){
    // Let the world be set up
    //super.setUp();
    // Set it up with a smaller world
    world = new World(400,400);
    world.setAutoRepaint(false); 

Can you please help me fix the error? thank you =)
You don't have the latest version of World.java – it's available in the mark-java-sources-v2.zip file. I've helped other students through this one. Mark Guzdial


Could we please discuss in class how to creat the excel spreadsheets? We use a lineForFile method like the one below? Please help!
   public String lineForFile(){
    PersonAgent first;
    first = (PersonAgent) agents.get(0);
    return (new Integer(first.infected())).toString();
  }

Sure! Yes, you create a version of this function. Look at WDSimulation for another version. Mark Guzdial

When I try to write out to the file, i get the following error "Can't write the data! Index 146, Size 146"

What does this all mean...? how can I fix it?
I've NEVER seen that error! Please bring your program (printed out or on laptop) to class or office hours today, and let's see what we can figure out. Mark Guzdial

Here's the World I currently use: World.java Mark Guzdial

i put in the world.java that you just put up and STILL get
File: C:\Documents and Settings\Owner\My Documents\School\1.2\CS1316\java-source\SimpleTurtle.java [line: 504]
Error: cannot resolve symbol
symbol : method getGraphics ()
location: interface ModelDisplay
:(

Me, too ;)


Nice tie today, Guzdial!

Thanks – my kids pick out most of my ties. Can you tell? :-) On getGraphics(), I think that you don't have the latest ModelDisplay and World. I'll upload my ModelDisplay in a moment... Mark Guzdial

Here's my current ModelDisplay. ModelDisplay.java Mark Guzdial


that fixed it! THANK YOU

So you're thinking, "Okay, I've got it running – now what do I change? What could make a difference AND be EASY!?" Here's a suggestion: Make the world 800x800, and move Europe and America accordingly. What if Europe were 300 pixels across? Would there be less overcrowding? In historical terms, if Europe were actually the size of Asia, would people have been more spread out and less likely to emigrate to America? You can explore alternate history here! Mark Guzdial

Still having the class Graphics, location interface ModelDisplay error... Sorry! I checked my preferences, reset them, imported the new versions of World, ModelDisplay, and SimpleTurtle. It also comes up with "TurtleWorld is not abstract and does not override method clearBackground() in ModelDisplay" when I try to open TurtleWorld, but I get the aforementioned public Graphics getGraphics(); error when I have the TurtleWorld class closed as well. I'm so sorry...
Could you send me Email with your Simulation and Agent subclasses? I can try to compile them here and see if there's an issue there. Do you want to talk on the phone? Send me a number and time this afternoon (Sunday) when to call you. Mark Guzdial

Could you please review how to run our simulations when we run out of memory?
Create a class (maybe "EmigrationSimulationRunner"?) with a "public static void main(String[] args)" in it, and put in the main() whatever you'd type in the interactions pane. Compile it. Quit DrJava. Open a Command window. cd into your java source directory. Execute "java EmigrationSimulationRunner". Now you're running without DrJava in memory. Mark Guzdial

Most common errors I'm seeing:

  public void act(){
  //** MARK ADDITION
  if (transit) {immigrate(); return;}/** So that immigrate gets called as long as in transit

  public void immigrate() { //** TWEAKED BY MARK
    transit = true;
    int myX = this.getXPos();
    if (myX > 199) //if in Europe
    { // ***Call this first step
      this.setBodyColor(Color.yellow); //Color is YELLOW if in-transit
      this.moveTo(170,this.getYPos());}
      if (myX == 170){
      //*** Call this the second step
       this.moveTo(140,this.getYPos());}
      if (myX==140){
      //*** Step 3: Arrive in America
      this.moveTo(100,this.getYPos());
      transit = false;
      American = true; // Though instance variables shouldn't be capitalized...
      this.setBodyColor(Color.blue); // Or whatever color you want Americans to be
      }
      if(randNumGen.nextInt(10) == 1)//10% of dying in Atlantic Ocean
        {this.die();}
    }

Hope this helps some! (I haven't compiled these yet, so there may be syntax errors in here.)


is the diease contagious? it the assignment just says a % get it. is it assumed that we should impliment contagiousness?

No, that's not required. However, if you want to implement contagiousness as one of your three scenarios, I think that that's a great idea! It should be pretty easy, since you already have code that does it. It's also realistic, and should make disease spread faster in crowded areas, which is realistic. Mark Guzdial


When i use the rule for Crop failure, most of the turtle have left europe and headed to america by the 30-40 time step. This would be fine other than the host of errors i get when america becomes too populated. Maybe my code for crop failure is wrong, take a look. stage 1 = living in europe; stage2=in transit; stage 3= living in america
if (randNumGen.nextInt(100) = 10)
{

stage2=true;
stage1=false;
stage3=false;
//this.remove();
}

Yes, given the set of rules I gave you, people abandon Europe pretty darn quickly. That makes for useful explorations for the other two scenarios. What makes Europe stay populated? A larger Europe (read further up this page for a hint on that one)? One where "overcrowding" is more tolerated (e.g., more than 3 steps) or needs to be more intense to be a bother (e.g., maybe it's close neighbors of 10 or more)? The reality is that cities in Europe do tend to be more densely populated than most of the US, so that would be a realistic direction to explore. Mark Guzdial


in my experiments i didn't find overcrowding to be the dominate force for emigration. crop failure over the course of 120 time steps could clean out india.
Good to know! There's another variable to explore! Mark Guzdial

When we set up our world how do we get all the people to be in Europe?
This was discussed earlier. Either specify the x,y when you create them, or move them in init(). Mark Guzdial

use the code in the political simuluation. but instead of moveTo(100,100); you can use Math.random();

I might have figured the answer to the question above:
for (int num = 0; num 150; num++)
{person = new Immigration(world,this);
person.moveTo(200 + randNumGen.nextInt(200), randNumGen.nextInt(400));}

But I get the following error message:
Error: cannot resolve symbol
symbol : variable randNumGen
location: class ImmigrationSimulation

Why?!?
Look at where randNumGen is declared, and where you're trying to use it. Why not do the move in init() where you know that you have randNumGen? Mark Guzdial


instead of randNumGen.nextInt(200), i would use ((int) Math.random()*200)
Yes, you can do that, but then, you'd lose the ability to change it to a normal distribution with nextGaussian(). Mark Guzdial

Thank you! Now it compiles, but all the turtles are appearing in the Very top. So, what numbers does random() produce? Between zero and one, right?

between zero and 1. then you multiply that decimal by the range you want. but if you want a range of 500 to 1000: you first multply random by the range (500) then add 500 to make the numbers between 500 and 1000.

If I'm trying to get a range between 0 and 400: (int) Math.random()400 right?
And for a range between 200 and 400: 200 + (int) Math.random()200 right?
Because this doesn't seem to be working!


Are you going to be available tomorrow after class as well? Or just before?
Are you talking to your anonymous correspondent or me? I'll be in my office between 3 and 4 today, too. Mark Guzdial

i know it works when you do it like this ((int) Math.random()*200 +200)


if (this.getXPos() 200) {
this.moveTo(200,this.getYPos());}
my Americans & Europeans stop moving when i call them back into their country. They just stop participating in the simulation :-\
That's a bummer – are they still in the agents list? Mark Guzdial

i'm not holding office hours today. -anonymous
All right, anonymous, but I'm going to have to dock your hours this week... :-)

now that i think about it... it may actually be ((int) Math.random()*200) +200. so the multiplication is done in ( ).

how do I count the intransit, americans, europeans? Should it be a linkedlist, int, array? Can I access it in my ImmigrantSimulation?

In my simulation class, can I do this?

public String lineForFile()
{
Immigrant first;
int americans = 0;
int euros = 0;
int intransit = 0;
for (int i = 0; i 150; i++)
{


first = (Immigrant) agents.get(i);
if (first.american)
{americans++;}

}
There are several ways of counting each type. The easiest way, in my opinion, is to have a boolen for being an American or not, and then testing that in a loop like the infected() method in PeopleAgent for the DiseaseSimulation. But I'm also seeing people keep track of REMOVEDkedLists of American, Europeans, and those in transit, and that works just fine. You could use the counting method, too – I think that that's perfectly valid. Mark Guzdial

I am having trouble compiling Agent. This is the line of code:
'currDistance = current.getDistance(this.getXPos(),this.getYPos());'
and this is the error:
File: C:\Documents and Settings\Mary Beth\My Documents\CS1316\java-source-11Feb\java-source\Agent.java [line: 129]
Error: cannot resolve symbol
symbol : method getDistance (int,int)
location: class Agent

Any suggestions?
Yup, you need the SimpleTurtle found in the .zip at SimpleTurtle.java.zip Mark Guzdial

There doesn't have to be any mystery about how Java is evaluating some expression – that's why you have the interactions pane!
> 200 + (200 * Math.random())
298.0137462449052
> (int) (200 + (200 * Math.random()))
376

code: g2 = (Graphics2D) modelDisplay.getGraphics();

1 error found:
File: C:\Documents and Settings\Mary Beth\My Documents\CS1316\java-source-11Feb\java-source\SimpleTurtle.java [line: 504]
Error: cannot resolve symbol
symbol : method getGraphics ()
location: interface ModelDisplay

I have ModelDisplay open...what is going on?


Using the new Model Display made it work...alas:)

I'm glad it's working now! Mark Guzdial



My DrJava only lets me record the counts as a txt sometimes. It will either do it right (about 5% of the time), or it will save the txt file but it's blank.
This isn't DrJava – it's just Java, and it's something in your code. Are you sure that you're naming your file .txt? Mark Guzdial

How do we set up boolean variables?
Declare them boolean. Initialize them in init(). Set them wherever you'd like. Mark Guzdial

Eep. So my simulation works (without everyone dying!!), but the .txt file has determined that regardless of where my agents are, or what color, they are all going to be recorded as Europeans, and I don't know why ...

public String lineForFile(){
int numInEurope = 0;
int numInTransit = 0;
int numInAmerica = 0;

for (int i = 0; i agents.size(); i++) {
EmigrantAgent currentAgent = (EmigrantAgent) agents.get(i);
if (currentAgent.inEurope()) {
numInEurope++;
} else if (currentAgent.inTransit()) {
numInTransit++;
} else if (currentAgent.inAmerica()) {
numInAmerica++;
}
}

return numInEurope + "\t" + numInTransit + "\t" + numInAmerica + "\r";

Is the problem in this part of the code, or is it somewhere sneakier? And if so, what could it be??

This looks right, Erin. Check that inTransit() and inAmerica() return the right things. I don't recommend using "\r" – that will only work on your Mac, and I suspect that both TA's grade in either Windows or REMOVEDux. Mark Guzdial

Aaaaaaaaaahhhhhhhhh........................................
I feel that way, too, sometimes. Mark Guzdial



Link to this Page