1. Listed next is the skeleton for a class named InventoryItem. Each inventory item has a name and a unique ID number: class InventoryItem private String name; private int uniqueItemID; Flesh out the...


I need some help with this coding problem


1. Listed next is the skeleton for a class named InventoryItem. Each inventory item has a name and a<br>unique ID number:<br>class InventoryItem<br>private String name;<br>private int uniqueItemID;<br>Flesh out the class with appropriate accessors, constructors, and mutators. The uniqueItemID 's are<br>assigned by your store and can be set from outside the InventoryItem class-your code does not have<br>to ensure that they are unique. Next, modify the class so that it implements the Comparable interface.<br>The compareTo() method should compare the uniqueItemID 's; e.g., the InventoryItem with item ID 5 is<br>less than the InventoryItem with ID 10. Test your class by creating an array of sample InventoryItem 's<br>and sort them using a sorting method that takes as input an array of type Comparable.<br>2. Define an interface named Shape with a single method named area that calculates the area of the<br>geometric shape:<br>public double area();<br>Next, define a class named Circle that implements Shape . The Circle class should have an instance<br>variable for the radius, a constructor that sets the radius, accessor/ mutator methods for the radius,<br>and an implementation of the area method. Also define a class named Rectangle that implements<br>Shape. The Rectangle class should have instance variables for the height and width, a constructor that<br>sets the height and width, accessor and mutator methods for the height and width, and an<br>implementation of the area method.<br>The following test code should then output the area of the Circle and Rectangle objects:<br>public static void main(String[] args)<br>{<br>Circle c = new Circle(4); // Radius of 4<br>Rectangle r = new Rectangle(4,3); // Height<br>showArea (c);<br>showArea (r);<br>4, width = 3<br>}<br>public static void showArea (Shape s)<br>double area = s.area();<br>System.out.println(

Extracted text: 1. Listed next is the skeleton for a class named InventoryItem. Each inventory item has a name and a unique ID number: class InventoryItem private String name; private int uniqueItemID; Flesh out the class with appropriate accessors, constructors, and mutators. The uniqueItemID 's are assigned by your store and can be set from outside the InventoryItem class-your code does not have to ensure that they are unique. Next, modify the class so that it implements the Comparable interface. The compareTo() method should compare the uniqueItemID 's; e.g., the InventoryItem with item ID 5 is less than the InventoryItem with ID 10. Test your class by creating an array of sample InventoryItem 's and sort them using a sorting method that takes as input an array of type Comparable. 2. Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape . The Circle class should have an instance variable for the radius, a constructor that sets the radius, accessor/ mutator methods for the radius, and an implementation of the area method. Also define a class named Rectangle that implements Shape. The Rectangle class should have instance variables for the height and width, a constructor that sets the height and width, accessor and mutator methods for the height and width, and an implementation of the area method. The following test code should then output the area of the Circle and Rectangle objects: public static void main(String[] args) { Circle c = new Circle(4); // Radius of 4 Rectangle r = new Rectangle(4,3); // Height showArea (c); showArea (r); 4, width = 3 } public static void showArea (Shape s) double area = s.area(); System.out.println("The area of the shape is area); +
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here