Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment, your Item class must also implement the Comparable interface. Assume, for example, your Item is called Circle, then the class header will
For this assignment, your Item class must also implement the Comparable interface. Assume, for
example, your Item is called Circle, then the class header will be as follows:
public class Circle implements Comparable
Add comapreTo method to your class. The method takes an Item object as input and returns either
or based on whether the input Item is equal to larger than, or smaller than the current Item,
respectively. Note that Items are to be sorted on the String attribute first then on the int attribute. For example, if your Item is a Circle that has color and radius as the String and int instance variables respectively. Assume you instantiated the following circle objects:
Circle c new Circlered;
Circle c new CircleRed;
Circle c new CircleBlue;
Then
ccompareToc returns because red is equal to Red and
ccompareToc returns because Blue red in alphabetical order ignoring the case.
Part :
Identify two subitems that are related to your Item. The names of your subitems must be meaningful and related to the main Item. For example, if your Item is Car, then the two subitems could be Truck and Sedan.
Implement ItemA class that extends Item as follows:
include one private instance variable of type integer.
implement a threearg constructor. The constructor must take input parameters in the following order: String, integer for the parent class then integer for the child class
implement getter and setter for the instance variable of your ItemA class
implement toString method that returns a string representation of the object where all instance variables are in one line and separated by tabs This method must call the toString method of Item. Do not include any text other than the values of the instance variables.
implement equals method. This method calls equals method from Item first and, if
ture, it checks the equality of the ItemAs instance variables.
Implement ItemB class that extends Item as follows:
include one private instance variable of type boolean.
implement a threearg constructor. The constructor must take input parameters in the following order: String, integer, then boolean.
implement getter and setter for the instance variable of ItemB class
implement toString that returns a string representation of the objects where all instance variables are in one line and separated by tabs This method must call the toString
method of Item. Do not include any text other than the values of the instance variables.
implement equals method. This method calls equals method from Item first and, if ture, it checks the equality of the ItemBs instance variables.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started