Formulate classes and use objects to store and compute tabular information.
A small grocery in your neighbourhood needs to track the items that it carries. An item is either perishable or non-perishable. Test data for three items is given in Table Q1.1 below:
The class Item is an abstract class. It has the following methods:
1.Getter and setter methods for both quantity on hand and cost price. Use the property decorator.
2.A method that changes the attribute for whether the item is on offer. If the item is not on offer, make the item to be on offer. If the item is on offer, make it to be not on offer.
3.A method for the selling price which is the sum of its cost price and a profit margin, dependent on the type of item.
4.A method for the offer price which is the selling price minus a discount. The discount rate is dependent on the type of item.
5.Abstract methods for computing the profit margin and the discount rate when the item is on offer.
6.A string method that returns all its attributes except the cost price as a string. The string also includes the selling price if the item is not on offer or the offer price if the item is on offer.
Two examples are shown here:
P009 Tan Baking Paper Available = 25 $3.90 (No Offer)
P009 Tan Baking Paper Available = 25 $3.51 **Offer**
The class Perishable has an additional attribute: expiryDate. It has the following methods:
1.A method that returns the profit margin which is 25% of its cost price.
2.A method that returns the discount rate when the perishable item is on offer. The discount is dependent on the number of days before expiry according to Table Q1.2:
The string method returns a string that includes the expiry date and the type of item.
Two examples are shown here:
P009 Real Rasins Available = 10 $2.50 (No Offer) Expiry date: 20 Nov 2018 Perishable Item
P009 Real Rasins Available = 10 $1.75 **Offer** Expiry date: 20 Nov 2018 Perishable Item
The class NonPerishable has no additional attribute. It has the following methods:
1.A method that returns the profit margin which is 30% of its cost price.
2.A method that returns the discount rate of 10% for non-perishable item on offer.
3.The string method returns a string that includes the type of item.
Two examples are shown here:
P009 Tan Baking Paper Available = 25 $3.90 (No Offer) Non-Perishable Item
P009 Tan Baking Paper Available = 25 $3.51 **Offer** Non-Perishable Item
(a) Define the class Item.
(b) Define the class Perishable.
(c) Define the class NonPerishable.
(d) Suppose there is a class Grocer that has a collection of Item objects called items. Define the following methods to perform the following tasks:
ist items.
Update the quantity on hand of an item when given an item code and a quantity to add to the quantity on hand. Return True if operation is successful and False otherwise.
(e) Discuss TWO (2) instances for each of THREE (3) SOLID principles you have applied. Explain how you have applied them in your solution.
Apply the principles of object-oriented design in solving the following problem. A module has a code, a name and has one or more assessment components. For each assessment component, the component type, the minimum required score for passing the component and the weightage are recorded. Test data for two modules is given in Table Q2.1 below:
You are given the class Module below:
You are given the class Module below:
The class Module has a module code and a module name as attributes. In addition, it has
a collection to record the component types, the minimum scores required to pass the components and their weightage. The following methods perform the following tasks:
(i) setMinScoreNWeight If the component is new, it adds the component into the collection, along with the minimum score and the weightage. If the component is existing, it updates the minimum score and the weightag given a component type, the new minimum score and the new weightage.
(ii) listMinScoresNWeights Return the details of the components (type, minimum score and weightage) for the module, as a string.
(a) Define a user exception class called ModuleScoreException
(b)Define the class ModuleScore which has a module as its attribute. In addition, it has a collection to record the scores for each component
(d)When a student did not perform a component, in this case, the quiz component for IT128, no score for that component is recorded as shown in Table Q2.2 below:
Include the following methods to perform the following tasks:
(e)Add a component and the score to the collection. The method raises an exception if the component is not a component for its module or if the new score is invalid. An invalid score is less than 0 or greater than 100.
(f)Update the score of a given a component of the module. The method raises an exception if the component is not a component for its module or if the new score is invalid.
(g)Remove a component and the score from the collection. The method raises an exception if the score of the component is not recorded yet for its module.
(h)Return a string with the details of the components, scores and relative weightages computed using the method getTotalWeig
(i)Return True if all the scores are at least the required minimum for the respective components. If any component is not cleared at the required minimum, return False
(j)Sum the weightages of the component in its module and return the sum. The method raises an exception if the sum is 0 or negative.