Arraylist data
              in 
             Programming Questions 
              •  
              2 years ago    
            
 
           
             hi there, i'm trying to make a program to create objects and then actively make an ellipse which is the average of the x and y positions of the objects. the idea is to use it to make an average of peoples' houses on a map and then find the best place to meet for everyone. here's what i've got so far but i can't work out how to get the average of the x and y positions in the arraylist
            
 
            - class House {
 float x;
 float y;
 float r = 10;
 boolean move;
-   public House() {
 x = random(width);
 y = random(height);
 }
-   public House(float sx, float sy) {
 x = sx;
 y = sy;
 }
-   void display() {
 fill(255);
 ellipseMode(CENTER);
 ellipse(x,y,r,r);
 }
-   void moveon() {
 if(mousePressed && dist(x,y,mouseX,mouseY) < 10) {
 move = true;
 }
 else {
 move = false;
 }
-     if(move) {
 x = mouseX;
 y = mouseY;
 }
 }
 }
- ArrayList houses;
- void setup() {
 size(800,600);
-   houses = new ArrayList();
 }
- void draw() {
 background(100);
-   for(int i=0; i<houses.size(); i++) {
 House h = (House)houses.get(i);
 h.display();
 h.moveon();
 h.moveon();
 }
-   average();
 }
- void keyPressed() {
 if(key == 'h') {
 houses.add(new House(mouseX,mouseY));
 }
 }
- void average() {
 for(int i=0; i<houses.size(); i++) {
 House h = (House)houses.get(i);
-     float ax = h.x(i) + h.x(j);
 float ay = h.y/houses.size();
-     ellipse(ax,ay,10,10);
 }
 }
- 
             any ideas?
            
 
              
              1  
            
 
            
 
 
          