Programming in Python using classes and objects Assessment
- Country :
Australia
Customer
- Class Customer
All customers have a unique ID and name. All existing customers are offered discounts. You
are required to write the class named Customer to support the following:
(i) Attributes ID and name
(ii) Constructor taking the value for ID and name as arguments
(iii) Appropriate getter/accessor methods for the attributes of this class.
(iv) A method get_discount(self, price) which should be an empty super method.
Product
- Class Product
This class is to keep track of information of different products in the warehouse. This class
supports the following information.
- ID A unique identifier for the product (e.g. P123)
- Name The name of the product which is always a single word.
- Price The price of the product.
- Stock The quantity of the product available in stock.
You need to define the appropriate variables and methods to support class Product. Note the
quantity in stock obviously will change. The price of a product may also be changed by the
user (a shop staff member).
Orders
- Class Order
This class is to handle customer orders. This class supports the following information of an
order.
- Customer who made the order (should you use ID, name or something else?)
- Product what has been ordered (how about this? Should you use ID or name?)
- Quantity The quantity of the product ordered by the customer.
This class can update information in the corresponding customer and product if necessary (be
careful with your overall class design). Define the appropriate variables and methods to support
the Order class.
You may need to find a way to manage an order containing multiple products, e.g. one person
ordered several items in one order. It is up to you how that can be handled. You need to
explain your approach as a part of the documentation.
Records
- Class Records
This class is the central data repository of your program. It supports the following information:
- a list of existing customers
- a list of exiting products
This class has a method readCustomers, which can read a comma separated file (CSV)
called customers.txt. See example below.
C1, Bryan,,,
C2, Zoran,,,
C3, Linda,,,
C4, Jack,,,
Customers are always in this format: ID, Name. There are three more fields reserved for
later parts. For this stage, these fields are empty. Customer IDs always start with letter C.
Assume there is never error in this file.
This class has another method readProducts that can read another CSV file called
products.txt and add the products stored in that file to the product list. See the example.
P1, Wine, 10.0, 50
P2, Chocolate, 5.00, 100
P3, Candle, 1, 1000
Products at the Pass level are always in this format: ID, Name, Price per Unit, In-
stock Quantity. Their IDs always start with letter P.
Assume there are no errors in products.txt.
This class has two methods findCustomer and findProduct. They are to search through
the lists to find out whether a given customer or a given product exists or not. If found, the
corresponding customer or product will be returned. Otherwise, None will be returned. Note
both customer and product can be searched by either ID or name.
This class also has methods listCustomers and listProducts. They can list all the
customers and products on screen. The display format is the same as that in the text files
shown above. These methods can be used to validate the reading from customers.txt and
products.txt.
Operations
This can be treated as the main class of you program. It supports a menu and can do the
following:
- When your program starts, it looks for customers.txt and products.txt in the
local directory. If found, data will be read into the program accordingly. The program will
display the menu. Error handling must be in place for file handling. If file reading is not
successful, the program will quit gracefully with an error message.
- From the menu, the user can list all customers and list all products. The display format is
the same as that specified in Records.
- Your program will allow the user to manually enter an order. You can assume no error in
input at this level. So you dont have to handle errors.
- The total price of the order can be displayed as a formatted message to the user. Note
appropriate discount should apply.
Unit price:
Total price:
- After making an order, the user can list the product information to see the reduction in the
stock quantity of that product.
- When a task is accomplished, the menu will appear again for the next task. The program
always exits gracefully from the menu, e.g. there is an exit option on the menu.