Sort Shapes 1. Make your Shapes comparable add: \"implements Comparable\" and cr
ID: 3547576 • Letter: S
Question
Sort Shapes
1. Make your Shapes comparable add: "implements Comparable" and create the method: public int compareTo(Object o){ ... }
to the abstract class Shape (so all the Shapes inherit it). For the comparison use the Shapes' area.
2. Create a driver (called Driver.java) that:
a) creates an array of shapes (ask user for the size)
b) in a loop, populate the array. (ask user what shape to create and the parameters need to create each shape)
c) print out the unsorted array
d) sort the array (I will post an implementation of SelectionSort in a file called SelectioSort.java)
e) print out sorted array
Extra credit
Use the authors ReadInt and ReadDouble to get all users input (in a file called ReadData.java)
One of the files posted is a Driver (main) that you can use to test the sorting of your shapes. It will create an array of shapes (parameters hard coded), print out shape, sort them, and then print them out agan.
Turn in only the files you created or modified (i.e. Shape.java and Driver.java). I can use your shapes from lab 6 (Point, Circle, Square, Cube, Cylinder) for the grading and I have (SelectionSort and ReadData).
Explanation / Answer
http://www.javaprogrammingforums.com/object-oriented-programming/33038-inheritance-variables.html
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.