Question: Part 1 : For this assignment, your Item class must also implement the Comparable interface. Example: public class Circle implements Comparable Add the Comparable.compareTo (
Part :
For this assignment, your Item class must also implement the Comparable interface. Example: public class Circle implements Comparable
Add the Comparable.compareTo method below to your class so you can sort Items.
public int compareTo Item o Compares this Item to the Item passed in the argument. This method returns either a negative integer, zero, or a positive integer based on whether the argument Item is less than, equal to or larger than the current Item, respectively.
Then
ccompareToc returns a negative int because red is equal to Red and
ccompareToc returns a negative int because Blue red in alphabetical order ignoring the case.
Part : Implement two subclasses that extend your Item class, well call them ItemA and ItemB here. Implement them as follows:
Instance Variables:
Give your ItemA subclass one instance variable that is a private String.
Give your ItemB subclass one instance variable that is a private Boolean.
Constructors: public ItemA String s Integer n Integer n is a constructor where n is the argument for the parent Item class, and n is the Integer for the ItemA subclass. public ItemB String s Integer n Boolean n is a constructor where n is the argument for the parent Item class, and n is the Integer for the ItemB subclass.
Methods: Implement a public getter and setter for each new instance variable. public String toString Returns a String representation of the object where all instance variables are on one line and are separated by tabs This method must call the toString method of Item. Do not include any text in the String other than the values of the instance variables. public boolean equalsItemA a Calls the equals method from Item first and, if true, it checks the equality of ItemAs Integer instance variable. public boolean equalsItemB b Calls the equals method from Item first and, if true, it checks the equality of ItemBs Boolean instance variable.
The rest of the worksheet are in the pictures.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
