Having trouble with my array

edited March 2015 in Using Processing

hello! i am new to this whole forum thing, but i was wondering if i might humbly ask for some assistance? i am trying to configure a sketch that uses data plotting and my array is acting up. any/all help would be greatly appreciated. thank you so much.


//Information from: http://www.oceaneconomics.org/LMR/topTenResults.aspx?selRegions=GL&selYears=2013&selOut=display&noepID=unknown


XML FishValue;//The xml file is declared
//ArrayLists for data sets
ArrayList Fish fishes = new ArrayList Fish();
int numOfFish = 10; //number of fish
int [] position = new int [numOfFish]; // array for position of each fish's data
int [] fishValue = new int [numOfFish]; // array for fish values
String [] fishNames = new String [numOfFish];// array for fish names
PFont f;
PImage BG;

void setup() {
  size(640,480);
  colorMode(HSB,360,100,100,100);
 textAlign(CENTER);
  background(0);
  BG = loadImage("GreatLakes.jpg");
  
  //loads the xml file
 FishValue = loadXML("FishValue.xml");
 XML [] Fish = FishValue.getChildren("Fish"); //information is recognized with this function
  
  
 for (int i = 4; i < numOfFish; i++){
   //the ValuePerFish given US dollar value of each fish
   //int ValuePerFish = 
   //the names of each fish
   fishNames[i] = Fish[i].getContent();
   //the spacing between fish data
   position [i] = (width/numOfFish)/2;
   position [i] += (i * (width/numOfFish)/1.5);
  }

 //elements
 for (int m = 0; m  position[0]-50 && xMouse < position[0]+50) {
      b.movement();
    b.display(70);
    //}
 
 //Points
  for (int i = 1; i < numOfFish; i++) {
    //This causes the points to connect
    int m = i - 1;
    //The x and y positions
    float xPos1 = position[i]-(width/10)/1.2;
   float xPos2 = position[i];
   float yPos1 = height/1.1-FishValue[m]*4;
    float yPos2 = height/1.1-FishValue[i]*4;
    //The lines of the line graph
   //strokeWeight(2);
   //stroke(360,20);
    //line(xPos1, yPos1, xPos2, yPos2);
   //stroke(360,10);
    //line(xPos1, height/1.1, xPos2, height/1.1);
  }
  //The names for each fish
  for (int i = 0; i < numOfFish; i++) {
    fill(170, 30, 90);
    text(fishNames[i], position[i], height/1.05);
 }
  //Value of each fish in US Dollars
  textSize(10);
  fill(360); //text color
  text("Value of each fish in U.S. Dollars", 100, 50);
}
 }

Answers

  • thanks. how about now?

  • edited March 2015
    • Since I don't have any of those files, I can't run your code!
    • And your variable names don't follow Java/Processing conventions.
    • Variable names follow lower case camel: FishValue should be fishValue and BG should be bg.
    • Constants like numOfFish should be all caps w/ underlines and static final:
      static final NUM_OF_FISH = 10;.
    • Rather than having lotsa arrays to represent 1 Fish entity, it's better to define a class Fish
      and use 1 Fish[] array only:

    static final NUM_OF_FISH = 10;
    final Fish[] fishes = new Fish[NUM_OF_FISH];
    
    class Fish {
      String name;
      int pos, val;
    
      Fish(String n, int p, int v) {
        name = n;
        pos  = p;
        val  = v;
      }
    }
    
  • i appreciate your input, but it still confuses me. not your fault, obviously. this class is hard for me.

Sign In or Register to comment.