POLYMORPHISM</o:p> Part A </o:p> Create a class InventoryItem which has </o:p> an int stockID </o:p> a String description </o:p> a double price </o:p> Write a...

1 answer below »

POLYMORPHISM

Part A

Create a class InventoryItem which has

  • an int stockID
  • a String description
  • a double price

Write a toString for this class that returns something like "Item 23. Footo the Wonder Boot Exploder ($22.99)"

Also write an equals method for this class. InventoryItems can only be equal to other InventoryItems, and only if they have the same price and description (even if stockID is different).


Part B

Create a class Book which inherits from InventoryItem and also has a String author (Book will use description to hold the book's title). toString for this class will return something like "Book 25, The Curse of the Flying Wombat by Constance deCoverlet ($12.95)".

Create a class MusicCD which inherits from InventoryItem and also has a String performer (it will use description to hold the CD's title). toString for this class will return something like "CD 12, Tommy Gnosis: Greatest Hits ($18.65)"


Part C


Create an array of 10 InventoryItems and fills it with various Books, MusicCD's, and other items for sale (you can make these up, you do not need to read them in from a user). Remember that you need to get space for the array separately from getting space for individual items.

Output the array/inventory list.

Answered Same DayApr 14, 2022

Solution

Kshitij answered on Apr 14 2022
11 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here