2023/11/13 13:44 CSC1034 Assessment 2 2023: Programming Portfolio 1 - CSC1034
CSC1034 Assessment 2 2023
To develop your expertise in using Python.
Learning Outcomes
This coursework will enable you to practice the following skills:
To implement and test your own solution
Good programming practice e.g., good use of variable and method names
Assignment
In this assignment, you will develop classes to demonstrate that you have learned and understood the module material, including:
1. Good use of object orientation
2. Validation of input
3. Using appropriate accessors and modifiers on instance variables (privacy)
4. Correct indentation
5. Good use of exception handling
6. Good use of variable names
7. The use of testing
8. Clear and appropriate use of code documentation
The coursework is not algorithmically challenging. The focus is on good design and good practice.
The coursework is not about development of an end-user application. You are developing classes that could be used for the development of an application. You should not develop a graphical user interface (GUI) or a command line interface (CLI). They are not necessary, and you will be given no credit for doing so.
Note the system specified is a deliberate simplification. It is not an accurate model of real-world systems. Your solution should correspond to the simplicity of the specification. You risk losing marks if you attempt to provide a more realistic model or provide a solution that is more complicated than necessary.
As always, it is best to consider the design in detail before writing code in Python. It is important that you write your code incrementally and test it carefully before continuing to add additional functionality.
Specification
In this assignment, you will implement a simple stock management and purchasing system. Your system should provide the following functionality:
-
A full list of all items and their details should be retrieved from the application.
-
Item details include name (string), category (string), perishable (boolean), stock (int), and
sell price (float)
-
Ensure that the system does not allow negative values for stock or sell price
-
-
Add, edit, and delete items.
1. Ensure that the system does not to allow duplicate items i.e., two or more items should nothave the same name.
-
You should be able to search the application for items by (completely matching) category,
perishable and sell price. This should return a list of all matches and their details.
-
The system should be able to apply discount (int, e.g., 10 means 10% off) to a subset of
existing items i.e., update the sell price
1. Ensure that the system only allows discount values between 0% and 50% -
Allow the user to purchase existing items
-
The system should notify the user of their total and update the stock when a purchase is
successful i.e., only when there is available stock
-
When the customer is a member, if they spend £50.00 or more, they get a 10% discount off
the total price, else they get a 5% discount
-
-
Store data in a file for subsequent re-use i.e., load/save data to/from csv file.
Tasks
To complete the system outlined above you will need to provide classes for the functionality described in this section. You must also test your solution.
Task 1
You need to create an Item class. You are provided with a template to help you get started (see item.py in Canvas). Please DO NOT change the file name or the class and method signatures.
All Item objects have the following functionality:
A constructor that initialises the Item object
A method to get the name (string, e.g., “Strawberry Jam”)
A method to get the category (string, e.g., “Food”)
A method to get the sell price (float, e.g., 0.99)
A method to determine if an item is equal to another item; if they are equal it returns true, else returns false. You should also implement the relevant hash method
Task 2
You need to create a ItemManager class. You are provided with a template to help you get started (see item_manager.py in Canvas). Please DO NOT change the file name or the class and method signatures.
All ItemManager objects have the following functionality: def __init__(self, items=None):
A constructor that initialises the ItemManager object. The items parameter is optional. If the items value is not provided (i.e., None), then initialise the list of items objects to be an empty list, else, make use of the values found in the given list of item objects.
def get_items(self):
A method to return the list of item objects
def __str__(self):
A string representation of the item manager
def __repr__(self):
The formal string representation of the item manager
def add_item(self, item):
This method adds an item to the item manager if it does not already exist
def remove_item(self, item):
This method removes an existing item from the item manager
def edit_item(self, old_item, new_item):
This method edits an existing item in the item manager
This method returns a list of all items that completely matches the given perishable (boolean) value
This method updates the list of item objects. Specifically, it applies a discount (int, e.g., 10) to each existing item specified in names (list of strings). There is no return.
def purchase_available_items(self, names, is_member):
This method updates the list of item objects. Specifically, for each existing item specified in names (list of strings), it deducts 1 from the stock value. This method also returns the total cost the user must pay for their purchases. If the customer is not a member (i.e., is_member = False), then return the total as calculated. Else, the customer is a member (i.e., is_member = True) and the following rule must be applied; if they spend £50.00 or more, they get a 10% discount off the total price, else they get a 5% discount.
def load_from_file(self, file_name):
This method reads a csv file (as specified in file_name, string) of item details and adds them to the list of item objects. You are provided with some sample data to help you get started (see sample_data.csv in Canvas).
def save_to_file(self, file_name):
This method writes to a csv file (as specified in file_name, string) all item details found in the list of item objects
Task 3
You should provide test cases for your classes. To do this you can use print statements. Note tests should be hard coded test cases i.e., do not use a CLI and/or GUI. You should test the normal case, boundary conditions, and exceptional cases.
Notes
Make sure that you use the Item and ItemManager classes provided for you.
You must not change the file names or the class and method signatures in the Item and
ItemManager classes. You can add extra methods if needed.
You can allow your methods to throw an error where needed.
If we cannot test your implementation because you have changed the file name(s), or
the class or method signature(s), then that corresponding task or method will score 0.
Mark Scheme
You will receive marks for:
The working functionality of your application (40%)
Clear and well written code (20%)
Evidence of correctness testing (20%)
Project documentation and good use of versioning (20%)
Deliverables
Your coursework must be submitted to the NESS system by the deadline specified. Note that NESS imposes deadlines rigorously, and even work that is a few seconds late (e.g., because of network delays caused by students all submitting at the last moment) will be flagged as late.
You should submit to NESS a zip file containing the following:
Your Python project source code (i.e., item.py, item_manager.py and any additional .py files)
Your README.md file
Your .git directory