I need help with Cartesian coordinates:
Write a Java interface named Centered with two abstract methods with no argument: one named getCenterX that returns a double, and another named getCenterY that returns also an double. The purpose of these two methods is to return the two Cartesian coordinates of the center of an object. Write a class called Rectangle that stores the Cartesian coordinates of two opposite corners of a rectangle, and write another class called Circle, that stores the Cartesian coordinates of the center, as well as the radius of the circle. Have both class implement the Centered interface. Write a test program using these two classes. Be sure your code compiles and runs as expected. Name your Java files Centered.java., Rectangle.java, Circle.java, TestCentered.java
Here is what I have so far:
public interface Centered {
public abstract double getCenterX();
public abstract double getCenterY();
}
public class Rectangle {
// The CartesianRectangle is an implementation of a Rectangle in the Cartesian coordinate system
// instance variables
// This representation of a rectangle stores the x and y coordinates of opposite corners of the rectangle.
public int[] xcoords; // stores the x-coordinates of one diagonal of the rectangle
public int[] ycoords; // stores the y-coordinates of one diagonal of the rectangle
// Constructor which takes the coordinates of the two opposite corners of the rectangle.
public Rectangle (int x1, int y1, int x2, int y2) {
// One way to initialize an array.
xcoords = new int[2];
xcoords[0] = x1;
xcoords[1] = x2;
int[] yArray = {y1,y2};
ycoords = yArray;
}
}
I need help with Cartesian coordinates:
Write a Java interface named Centered with two abstract methods with no argument: one named getCenterX that returns a double, and another named getCenterY that returns also an double. The purpose of these two methods is to return the two Cartesian coordinates of the center of an object. Write a class called Rectangle that stores the Cartesian coordinates of two opposite corners of a rectangle, and write another class called Circle, that stores the Cartesian coordinates of the center, as well as the radius of the circle. Have both class implement the Centered interface. Write a test program using these two classes. Be sure your code compiles and runs as expected. Name your Java files Centered.java., Rectangle.java, Circle.java, TestCentered.java