Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Problem b (PA4b.java) Your task is to write in JAVA program that will output colored shape vertices in CSV format (comma-separated value[1];...

Problem b (PA4b.java)

Your task is to write in JAVA program that will output colored shape vertices in CSV format (comma-separated value[1]; something Microsoft Excel can open!). To build up to this capability, you will be implementing a set of classes, including two subclasses. Here is the recommended sequence:

1.       To start, implement the Point2D class. It is quite similar to the class in a previous assignment, but now has you override the equals method to detect points that represent the same location, within a distance threshold.

2.      Then implement the Rectangle class, which is a subclass of Shape2D (provided for you). You will use simple arithmetic to implement such functionality as computing area, perimeter, and center point. The vertices (think corner points) for a rectangle are expected to start at the lower-left corner and proceed clockwise. Two rectangles are considered "equal" if they have lower-left and upper-right points that are "equal".

3.      Now move on to the Triangle class, which is also a subclass of Shape2D. The math here can get a little more complex for area[2] and center point (centroid[3]). An axis-aligned bounding box (AABB[4]) is simply the rectangle that most closely bounds the vertices of the triangle. The vertices should be returned in the order they were provided in the constructor.

4.      Now move on to the PA4b class. The shapeVertices method receives an array of Shape2D objects and must produce a string which includes all the vertices in CSV format (on each line: "color",x,y). If the method encounters a triangle object, it should include the vertices of the AABB after the triangle. This is an opportunity to experiment with polymorphic code. When this method is complete, proceed to main - validate command-line arguments for a single colored triangle and use the method you just completed to output the corresponding CSV to the terminal.

Here are example runs of a completed program:

$ java edu.wit.cs.comp1050.PA4b

Please supply correct inputs: color x1 y1 x2 y2 x3 y3

$ java edu.wit.cs.comp1050.solution.PA4b 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

Note: if you copy-paste the output into a file (typically with a .csv extension) and open it in Excel, you could then plot the last two columns using an XY plot!

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question