Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement the attached Point class. Upload Point.java. Use the classes down belo

ID: 3878490 • Letter: I

Question

Implement the attached Point class. Upload Point.java. Use the classes down below:

public class Point {

protected static int maxX = 400, maxY = 400, minX = 0, minY = 0; //default values

protected double x,y; // location of the Point

public Color color; // the color used to draw the Point public Point()

{ // call the two-parameter constructor with random x and y values between 0 and maxX, maxY.

}

public Point(double x, double y) {

// call the setters for x and y

}

public double getX() {

// return the value of this.x

}

public double getY() {

// return the value of this.y

}

public void setX(double x) {

// set this.x to x or to nearest legal value

}

public void setY(double y) {

// set this.y to y or to nearest legal value

}

// setters for maxX etc.

static public void setMaxX(int maxX) {

// set Point.maxX to parameter maxX. Or to Point.minX if parameter < Point.minX.

}

static public void setMaxY(int maxY)

{

// set Point.maxY to parameter maxY. Or to Point.minY if parameter < Point.minY.

}

static public void setMinX(int minX) {

// similar to setMaxX

}

static public void setMinY(int minY) {

// similar to setMaxY

}

// getters for maxX etc.

public static int getMaxX() {}

public static int getMaxY() {}

public static int getMinX() {}

public static int getMinY() {}

public int roundX() {return Util.round(x);}

public int roundY() {return Util.round(y);}

public String toString() {

// return a String of the form (40,75) (the first number is x and the second number is y).

}

public void draw(Graphics g) {

// draw a tiny disk (~3 pixels in diameter) with its center at location x,y

}

public void move(Vect a) {

// move the Point by a.vx and a.vy

}

public boolean equals(Object o) {

// return true of o refers to an object of type Point with same x and y values as this

}

public double getDistance(Point p) {

// return the distance between this and p

}

}

Explanation / Answer


Given below is the completed code for the question. It uses 2 other classes Util and Vect which is not provided here in the question. I guess you should be having them in order to compile this code.
Please do rate the answer if it was helpful. Thank you
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i

import java.awt.Color;
import java.awt.Graphics;
public class Point {
protected static int maxX = 400, maxY = 400, minX = 0, minY = 0; //default values
protected double x,y; // location of the Point
public Color color; // the color used to draw the Point
public Point()
{
// call the two-parameter constructor with random x and y values between 0 and maxX, maxY.
this(minX + Math.random() * (maxX - minX), minY + Math.random() * (maxY - minY ));
}
public Point(double x, double y) {
// call the setters for x and y
setX(x);
setY(y);
}
public double getX() {
// return the value of this.x
return x;
}
public double getY() {
// return the value of this.y
return y;
}
public void setX(double x) {
// set this.x to x or to nearest legal value
this.x = x;
}
public void setY(double y) {
// set this.y to y or to nearest legal value
this.y = y;
}
// setters for maxX etc.
static public void setMaxX(int maxX) {
// set Point.maxX to parameter maxX. Or to Point.minX if parameter < Point.minX.
Point.maxX = maxX;
}
static public void setMaxY(int maxY)
{
// set Point.maxY to parameter maxY. Or to Point.minY if parameter < Point.minY.
Point.maxY = maxY;
}
static public void setMinX(int minX) {
// similar to setMaxX
Point.minX = minX;
}
static public void setMinY(int minY) {
// similar to setMaxY
Point.minY = minY;
}
// getters for maxX etc.
public static int getMaxX() {return maxX;}
public static int getMaxY() {return maxY;}
public static int getMinX() {return minX;}
public static int getMinY() {return minY;}
public int roundX() {return Util.round(x);}
public int roundY() {return Util.round(y);}
public String toString() {
// return a String of the form (40,75) (the first number is x and the second number is y).
return "(" + roundX() + "," + roundY() + ")";
}
public void draw(Graphics g) {
// draw a tiny disk (~3 pixels in diameter) with its center at location x,y
g.setColor(color);
g.fillOval(roundX(), roundY(), 3, 3);
}
public void move(Vect a) {
// move the Point by a.vx and a.vy
x += a.vx;
y += a.vy;
}
public boolean equals(Object o) {
// return true of o refers to an object of type Point with same x and y values as this
if(o instanceof Point)
{
Point p = (Point)o;
if(x == p.x && y == p.y)
return true;
else
return false;
}
else
return false;
}
public double getDistance(Point p) {
// return the distance between this and p
double dx = x - p.x;
double dy = y - p.y;
return Math.sqrt(dx * dx + dy * dy);
}
}