[Solved]Java Task Write Program Output Colored Shape Vertices Csv Format Comma Separated Value 1 S Q37038417
JAVA
Your task is to write a program that will output colored shapevertices in CSV format (comma-separated value[1]; somethingMicrosoft Excel can open!). To build up to this capability, youwill be implementing a set of classes, including two subclasses.Here is the recommended sequence:
- To start, implement the Point2D class. It isquite similar to the class in a previous assignment, but now hasyou override the equals method to detect pointsthat represent the same location, within a distance threshold.
- Then implement the Rectangle class, which is asubclass of Shape2D (provided for you). You willuse simple arithmetic to implement such functionality as computingarea, perimeter, and center point. The vertices (think cornerpoints) for a rectangle are expected to start at the lower-leftcorner and proceed clockwise. Two rectangles areconsidered “equal” if they have lower-left and upper-right pointsthat are “equal”.
- Now move on to the Triangle class, which isalso a subclass of Shape2D. The math here can geta little more complex for area[2] and center point (centroid[3]).An axis-aligned bounding box (AABB[4]) is simply the rectangle thatmost closely bounds the vertices of the triangle. The verticesshould be returned in the order they were provided in theconstructor.
- Now move on to the PA4b class. TheshapeVertices method receives an array ofShape2D objects and must produce a string whichincludes all the vertices in CSV format (on each line:“color”,x,y). If the method encounters a triangleobject, it should include the vertices of the AABB after thetriangle. This is an opportunity to experiment with polymorphiccode. When this method is complete, proceed tomain – validate command-line arguments for asingle colored triangle and use the method you just completed tooutput the corresponding CSV to the terminal.
Please supply correct inputs: color x1 y1 x2 y2 x3y3
blue 0 0 0 1 1 0
“blue”,0.000,0.000
“blue”,0.000,1.000
“blue”,1.000,0.000
“blue”,0.000,0.000
“blue”,0.000,1.000
“blue”,1.000,1.000
“blue”,1.000,0.000
public class PA4b {
/**
* Error if incorrect command-line arguments aresupplied
*/
public static final String ERR_USAGE = “Please supplycorrect inputs: color x1 y1 x2 y2 x3 y3”;
/**
* Number of command-line arguments
*/
public static final int NUM_ARGS = 7;
/**
* Produces a string representing
* all vertex information in CSV
* format:
* “color”,x,y
*
* For all shape vertices,
* including axis-aligned bounding
* boxes for any included triangles
*
* @param shapes array of shapes
* @return string of CSV information
*/
public static String shapeVertices(Shape2D[] shapes){
return “”; // replace with yourcode (use a StringBuilder for efficiency!)
}
/**
* Outputs vertex information in CSV
* format about the triangle supplied
* via command-line arguments, including
* its axis-aligned bounding box
*
* @param args command-line arguments: color x1 y1 x2y2 x3 y3
*/
public static void main(String[] args) {
// replace with your code
}
}
public class Point2D {
/**
* Constructor to initialize coordinates
*
* @param x x value
* @param y y value
*/
public Point2D(double x, double y) {
// replace with your code
}
/**
* Get the x coordinate
*
* @return x coordinate
*/
public double getX() {
return 0; // replace with yourcode
}
/**
* Get the y coordinate
*
* @return y coordinate
*/
public double getY() {
return 0; // replace with yourcode
}
/**
* Gets a String representation
* of the coordinate in the form
* “(x, y)” (each with three decimal
* places of precision)
*
* @return “(x, y)”
*/
@Override
public String toString() {
return “”; // replace with yourcode
}
/**
* Returns true if provided another
* point that is at the same (x,y)
* location (that is, the distance
* is “close enough” according to
* Shape2D)
*
* @param o another object
* @return true if the other object is a point and thesame location (within threshold)
*/
@Override
public boolean equals(Object o) {
return false; // replace with yourcode
}
/**
* Method to compute the Euclidean/L2
* distance between two points in 2D
* space
*
* @param p1 point 1
* @param p2 point 2
* @return straightline distance between p1 andp2
*/
public static double distance(Point2D p1, Point2D p2){
return 0; // replace with yourcode
}
/**
* Method to compute the Euclidean
* distance between this point
* and a supplied point
*
* @param p input point
* @return straightline distance between this point andp
*/
public double distanceTo(Point2D p) {
return 0; // MUST call distanceabove with this point
}
}
public abstract class Shape2D {
final private String color;
final private String shapeName;
final public static double THRESH = 1.0E-5;
/**
* Returns true if two numbers
* are considered close enough
*
* @param a value 1
* @param b value 2
* @return true if a and b are considered closeenough
*/
public static boolean closeEnough(double a, double b){
return Math.abs(a-b) <=THRESH;
}
/**
* Constructs the shape
*
* @param color shape color
* @param shapeName name of the shape (e.g. Triangle,Rectangle, etc.)
*/
public Shape2D(String color, String shapeName) {
this.color = color;
this.shapeName = shapeName;
}
/**
* Gets the color of the shape
*
* @return shape color
*/
final public String getColor() {
return color;
}
private String vToString() {
final StringBuilder sb = newStringBuilder();
final Point2D[] v =getVertices();
if (v.length > 0) {
sb.append(v[0]);
for (int i=1; i sb.append(String.format(“, %s”, v[i]));
}
}
return sb.toString();
}
/**
* A friendly text representation of the shape
*
* @return something like “Red Rectangle @ ((0.000,0.000), (0.000, 1.000), (1.000, 1.000), (1.000, 0.000)):center=(0.000, 0.000), perimeter=4.000, area=1.000”
*/
@Override
final public String toString() {
return String.format(“%s %s @ (%s):center=%s, perimeter=%.3f, area=%.3f”,
color, shapeName, vToString(), getCenter(),getPerimeter(), getArea());
}
/**
* Gets the area of the shape
*
* @return area
*/
public abstract double getArea();
/**
* Gets the perimeter of the shape
*
* @return perimeter
*/
public abstract double getPerimeter();
/**
* Gets the center of the shape
*
* @return center of the shape
*/
public abstract Point2D getCenter();
/**
* Gets the vertices of the shape
*
* @return shape vertices
*/
public abstract Point2D[] getVertices();
}
public class Triangle extends Shape2D {
/**
* Constructs a triangle given
* three points
*
* @param color color
* @param p1 point 1
* @param p2 point 2
* @param p3 point 3
*/
public Triangle(String color, Point2D p1, Point2D p2,Point2D p3) {
super(color, “”); // replace withyour code
}
/**
* Returns the axis-aligned
* bounding box for this
* triangle
*
* @return axis-aligned bounding box
*/
public Rectangle getAxisAlignedBoundingBox() {
return null; // replace with yourcode
}
@Override
public double getArea() {
return 0; // replace with yourcode
}
@Override
public double getPerimeter() {
return 0; // replace with yourcode
}
@Override
public Point2D getCenter() {
return null; // replace with yourcode
}
@Override
public Point2D[] getVertices() {
return null; // replace with yourcode
}
public class Rectangle extends Shape2D {
/**
* Constructs a rectangle given two points
*
* @param color rectangle color
* @param p1 point 1
* @param p2 point 2
*/
public Rectangle(String color, Point2D p1, Point2D p2){
super(color, “”); // replace withyour code
}
/**
* Returns true if provided
* another rectangle whose
* lower-left and upper-right
* points are equal to this
* rectangle
*/
@Override
public boolean equals(Object o) {
return false; // replace with yourcode
}
/**
* Gets the lower-left corner
*
* @return lower-left corner
*/
public Point2D getLowerLeft() {
return null; // replace with yourcode
}
/**
* Gets the upper-right corner
*
* @return upper-right corner
*/
public Point2D getUpperRight() {
return null; // replace with yourcode
}
@Override
public double getArea() {
return 0; // replace with yourcode
}
@Override
public double getPerimeter() {
return 0; // replace with yourcode
}
@Override
public Point2D getCenter() {
return null; // replace with yourcode
}
@Override
public Point2D[] getVertices() {
return null; // replace with yourcode
}
}
Expert Answer
Answer to JAVA Your task is to write a program that will output colored shape vertices in CSV format (comma-separated value[1]; so… . . .
OR

