a) create a Node Object using generics. Then use the class Shape as the tag (<Sh
ID: 3540666 • Letter: A
Question
a) create a Node Object using generics. Then use the class Shape as the tag (<Shape>) when you create the Node Objects. Your Node Objects should implement Comparable. Define the compareTo method based on the area of the 2 shapes that you are comparing.
b) create a method that reads in from a text file whose format is as follows:
Classname:parameter list
for example
Square: 5
Circle: 3
Right Triangle: 4, 2
When reading in these lines, the 1st line should cause your program to create a Node with a Square object who has a side of 5.
The 2nd line should cause you to create a Node with a Circle Object with a radius of 3
The 3rd line should cause you to create a Node with a RightTriangle Object with a base of 4 and a height of 2.
c) Create a findMax function that will compare nodes. Do not just save the current maximum area and compare areas. I want you to call the compareTo function on the Nodes. That method should compare the areas of each of the shapes and return 0 if the areas are the same, a negative number if the object that the method is called upon (ie. "this") is less than the object passed as a parameter, or a positive number if the object that the method is called upon is greater than the object passed as a parameter. (hint: you can use something like "return that.getData().getArea() - this.getData().getArea();" where "that" is the name of the object passed)
Explanation / Answer
Can you mention the filename we need to use here?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.