Assignment 2 Solution



Assignment 2 Skills

Using Generics

Using Inheritance

Assignment 2 Background

Consider the software system from Assignment 1 that models a StoreShelf, and a Product. We would like to make a couple of modi cations to this system.

Create a Generic class Bucket to can store any type of object. The bucket has one data item: the object to store. The Bucket should have the functionality described:

  1. a default constructor.

  1. a method addItem that takes 1 parameter: the item to store.

  1. a method isEmpty that takes 0 parameters: and return true if the bucket is empty and false if there is an item stored in it.

We also wish to obtain products that have a limited shelf life. Create a new class PerishableProduct, that inherits from Product. In addition it should have new member variables called daysOnShelf, daysToKeep. It should have one constructor that takes 4 parameters: the product name, price, count, and days to keep.

Assignment 2 Requirements

20% – Write the Bucket class using Generics.

20% – Bucket class has methods described.

20% – Write the PerishableProduct class using Inheritance.

20% – PerishableProduct class has only 1 constructor as speci ed.

10% – daysOnShelf and daysToKeep are of an appropriate type.

10% – Provide comments where appropriate.

Assignment 2 Submission Submit on Blackboard:



Required Each submitted le should include your name and a statement that this is your own work. This should appear as a comment at the beginning of any code le.