IFN581 Assessment 2 - Programming Assignment
Weighting: 40% Total Marks: 100 Individual
Due Date: 11.59 pm 24th Oct 2025
(Eligible for 48 hours Automatic Extension)
Submission: Online via QUT Canvas: One Submission only
1. You should not use any Python concepts which have not been taught as part of this Unit.
2. Do not use Internet Resources including ChatGPT and AI.
Any breach of these two conditions will be considered as an act of major academic misconduct and could incur severe penalty.
This Programming Assignment is split into three Parts.
All these three parts are to be part of one Python program file with extension .py.
Part A: Define the Product class with category definitions, attributes, getter/setter methods for product_id, a constructor, and a str() method.
Part B: Write functions and a main program to input, validate, display, and filter a list of products using the Product class.
Part C: Implement file operations to save/load products and display them.
Part A: Define a Product Class in Python
You are required to create a Python class named Product that models product information in a retail shop, following these specifications:
1. Define two static lists (class attributes) to represent the valid product categories:
categoryCodes = ["GR", "HB", "CF", "EL", "HL", "OT"]
categoryNames = ["Groceries", "Health & Beauty", "Clothing & Footwear", "Electronics", "Home & Living", "Others"]
2. The Product class must include the following instance attributes:
product_id: a private attribute, string (e.g., "EL101"), accessed via get_product_id() and modified via set_product_id().
category_name_of_product: a read-only attribute, string, derived from the product_id and modified via set_product_id().
product_name: a public attribute, string (e.g., " Bluetooth Speaker").
quantity: a public attribute, integer (number of items in stock).
price: a public attribute, float (unit price).
3. Product ID Validation Logic
Implement getter and setter for product_id. The setter must:
· Extract the first two characters from the given product_id and use them to look up the corresponding category name. There is no need to store the category code as a separate attribute.
· If the code exists in categoryCodes, assign it as-is and set the corresponding category_name_of_product.
· If the code does not exist, automatically change the category code to "OT" (Others) and rewrite the product_id with "OT" followed by the number part.
Examples:
· Input "EL205" → Product ID: EL205, Category: Electronics
· Input "ZZ101" → Product ID rewritten as OT101, Category: Others
4. Constructor (__init__ ()) method: Implement a constructor that allows both default and parameterized instantiation:
def __init__(self, product_id=None, product_name="", quantity=0, price=0.0)
· If no arguments are provided, initialize with default values.
· If arguments are provided, assign them accordingly.
Examples:
· p1 = Product() # Create a product with default values
· p2 = Product("EL205", "Bluetooth Speaker", 1, 49.99)
5. String Representation (__str__ ()) method:
Override the __str__ method to provide a nicely formatted string output when the product object is printed:
Example output:
Product ID: EL205 | Category: Electronics | Name: Bluetooth Speaker | Quantity: 1 | Price: $49.99
Part B: Program Functions
Write a main program that performs the following tasks using the Product class:
1. display_introduction(): Displays your name, student ID, and a greeting message surrounded by a border. You don’t need to ask user to input these values. For example:
****************************************
* Name: Lara Dev *
* Student ID: 12345678 *
* Hello, welcome to my program! *
****************************************
2. input_value(min, max):
Prompts for an integer input between min and max (inclusive). Re-prompts until valid.
3. is_valid(product_id):
Returns True if the string is 5 characters long, starts with two uppercase letters, and ends with three digits.
4. get_product_data(n):
Repeatedly prompts user to enter details for n products. Validates each product ID using is_valid() before assigning via set_product_id(). Returns a list of Product objects. When prompting for quantity, restrict the valid range to 1–50 items.
5. display_all_products(products):
Prints details of all products using each product’s __str__() method.
6. get_product_lists(products):
Allows user to filter and view products by category code and shows the total per category.
Part C: File Operations & Dictionary Grouping
1. save_products_to_file(filename, products):
Writes all product records to a file in comma-separated format.
2. load_products_from_file(filename):
Reads from the file and reconstructs Product objects. Returns a list.
3. main() Function Tasks:
Your main() function must execute the following in order:
a. Call display_introduction()
b. Prompt the user for number of products (1–40) using input_value()
c. Call get_product_data() to input product details, using the number obtained in Part C, Task 3.b as the argument.
d. Call display_all_products() to show all entered products
e. Save products to "Student_Surname_Product.txt" using save_products_to_file()
f. Allow the user to repeatedly search for products by category using get_product_lists(), until they enter '!' to stop.
g. Load products back from file using load_products_from_file()
h. Display the loaded products by calling display_all_products().
In completing your assignment, please take note of the following:
· You should develop your code using simple logic.
· Test your code using your own test data covering multiple data sets.
· Your final code should not have any compilation/execution errors.
Project Deliverable:
Program Code
Upload the file with .py extension onto Canvas using IFN581 Assessment 2 Programming Assignment link under Assessment 2 in Modules.
The link will be available only from Monday 20th October 2025.
You can upload only ONCE.
Note:
Assessment submitted after the due date without an approved extension will not be marked and will receive a grade of 1 or 0%. If special circumstances prevent you from meeting the assessment due date, you can apply for an extension through the Student Services in Faculty of Science. If you do not have an approved extension you should submit the work you have completed by the due date and it will be marked against the assessment criteria. Do not send us email requesting for extension.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。