Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) create a Node Object using generics. Then use the class Shape as the tag (<Sh

ID: 3540667 • 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

// Abstract node in a linked list public abstract class Node { private Node m_next; public Node Next { get { return m_next; } } public Node(Node next) { m_next = next; } } // Node in a linked list. Different nodes in the same list may carry data // of different types. public class Node : Node { private T m_data; public T Data { get { return m_data; } } public Node(T data, Node next) : base(next) { m_data = data; } } // Abstract pair. public abstract class Pair { } // Pair containing two values, possibly of different types. public class Pair : Pair { private TFirst m_first; private TSecond m_second; public Pair(TFirst first, TSecond second) { m_first = first; m_second = second; } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote