Trash

 

trashItem objects have a weight and an indicator showing whether they are recyclable or not.

A trashItem object can be constructed as follows:

t = trashItem(13.7,True)

Task 1 - Class design

Design the trashItem class. Include a constructor method and accessor methods for the two class variables.

Test you design by writing a program that constructs a trashItem object and displays the weight and recyclable indicator.

Save your solution as trash-1.py

Task 2 - Containment

A trashCan object stores an array of trashItems up to a maximum of 10 items.

When a trashCan is constructed, it constructs an array of 10 elements, each storing None.

The trashCan class has the following methods:

method description
addItem This method takes 2 parameters, a weight and a recyclable indicator. If the array of trashItems is not full, ie there is still atleast one None in the array, a new trashItem object is constructed and replaces the next available None in the array. If the array is already full, a message Can is full of items is displayed.
removeItem This method replaces the latest trashItem added to the trashCan with None ie consider a trashCan to be a STACK data structure ie Last-In First-Out
getItem This method takes 1 parameter, an array index value. If the value is valid, ie between 0 and 9 inclusive, the trashItem at that index is returned, or None is returned.
sortItems This method sorts the trashCan in the heaviest order of items

Design the trashCan class.

Test your design by adding and removing trashItems to a trashCan. Make sure you can never remove a trashItem if the trashCan is empty, and you can never add a trashItem if the trashCan is full.

Save your solution as trash-2.py

Task 3 - Pseudocode

Write pseudocode for the method addItem in the trashCan class.

Testing

Make sure you are thoughtful when testing your solution.

If your code has a validation check, test your code with acceptable/valid data and unacceptable/invalid data.