please send edited code Mainjava package part2 import javaut

please send edited code

Main.java

package part2;

import java.util.Random;

public class Main {

   static final int NUM = 10;

  

   public static void main(String[] args) {

       EZ.initialize(600, 600);

      

       Data [] datapoints = new Data[NUM];

      

       Random rg = new Random();

       for (int i=0; i<NUM; i++) {

           datapoints[i] = new Data(rg.nextInt(600), rg.nextInt(600));

       }

      

       for (int i=0; i<NUM; i++) {

           datapoints[i].draw();

       }

       Data.drawCenter();

       Data.print();

   }

}

Data.java

package part2;

import java.awt.Color;

public class Data {

   // static variables

  

   // member variables

  

   // static functions

   public static void print() {

   }

  

   public static void drawCenter() {

   }

   // member functions

   public Data(int _x, int _y) {

   }

  

   public void draw() {

   }

  

}

Part 2- Static In the attached project, look at part 2. You need to complete the Data class (and you can use Main to test it). Every time we create a new Data object, our static variables will keep track of the number of data points and what is their average center point. In Data.iava 1. Add 3 static variables: an integer called count, and floats called centerX and centerY (their initial value should be 0) Add 2 member variables: integers called x and y Make the static function print0 print out how many data points there are and what is the center point For example: There are 10 data points Centered at (360.0, 388.2) 2. 3. 4. Make drawCenter) draw a red circle (width and height can be 20) at centerX, centerY. You will need to cast them into integers.

Solution

Main.java
--------------
import java.util.Random;

public class Main {

   static final int NUM = 10;



   public static void main(String[] args) {

       Data [] datapoints = new Data[NUM];

       Random rg = new Random();

       for (int i=0; i<NUM; i++) {

           datapoints[i] = new Data(rg.nextInt(600), rg.nextInt(600));

       }

       for (int i=0; i<NUM; i++) {

           datapoints[i].draw();

       }

       datapoints[NUM-1].drawCenter()

;

       Data.print();

   }

}

Data.java
--------------


public class Data{
   static int count=0;
   static float centerX=0.0f, centerY=0.0f;

   int x,y;

   public static void print(){
       System.out.println(String.

format(\"There are %d data points.\",count));
       System.out.println(String.format(\"Centered at (%f,%f)\",centerX,centerY));
   }
  
   public void drawCenter(){
       // We need to initialize a Graphics object g here and call g.drawOval((int)centerX-20/2,(int)centerY-20/2,20/2,20/2)
   }
  
   public Data(int _x,int _y){
       this.x = _x;
       this.y = _y;
       centerX = (count*centerX+x)/(count+1);
       centerY = (count*centerY+y)/(count+1);
       count++;
   }

   public void draw(){
       // First, use g.drawLine(this.x,this.y,centerX,centerY)
       // Second, use g.drawRect(this.x,this.y,20,20)
   }
}

Comments: It is not clear whether the program should be created as an applet. If yes, then calling the applet class from another java application class looks unconventional.
Please clarify the same and use the simple ready-to-use instructions in the Data.java alongwith some appropriate changes in the Data constructor to get the whole thing working.

please send edited code Main.java package part2; import java.util.Random; public class Main { static final int NUM = 10; public static void main(String[] args)
please send edited code Main.java package part2; import java.util.Random; public class Main { static final int NUM = 10; public static void main(String[] args)
please send edited code Main.java package part2; import java.util.Random; public class Main { static final int NUM = 10; public static void main(String[] args)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site