Answered step by step
Verified Expert Solution
Link Copied!

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
0,-1, or 1 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 c1= new Circle(red,10);
Circle c2= new Circle(Red,20);
Circle c3= new Circle(Blue,20);
Then
c1.compareTo(c2) returns -1 because red is equal to Red and 10<20.
c3.compareTo(c2) returns -1 because Blue < red in alphabetical order ignoring the case.
Part 2:
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:
1. include one private instance variable of type integer.
2. implement a three-arg constructor. The constructor must take input parameters in the following order: String, integer (for the parent class), then integer (for the child class).
3. implement getter and setter for the instance variable of your ItemA class
4. 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.
5. 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:
1. include one private instance variable of type boolean.
2. implement a three-arg constructor. The constructor must take input parameters in the following order: String, integer, then boolean.
3. implement getter and setter for the instance variable of ItemB class
6. 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.
7. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

Discuss the goals of financial management.

Answered: 1 week ago