Thompson Rivers University
Assignment Overview: Polymorphism & Interfaces
Assignment 2 Product - SM 2025This assignment focuses on polymorphism and interface implementation in Java. You will design and implement a console-based application to manage food product records with the following key requirements:
Product Data Management
Each product record stores a code, description, price, and category.
Categories include
UNCLASSIFIEDplus three user-defined types (e.g.,MEAT,DAIRY,PRODUCE).
Security via Password Locking
Product records are protected by a password.
You must be able to set, lock, unlock, and check the lock state for each record.
Interface Design
Categoryinterface: declares integer category constants and methods to set/get a product’s category.PasswordLockableinterface: declares methods to set a password, lock/unlock the record, and query its lock state.Comparable<Product>interface: enables comparison of two products based on price.
Class Implementation
Create a
Productclass that:Implements all three interfaces.
Defines private attributes for code, description, price, category, password, and locked state.
Allows attribute updates only when unlocked, otherwise prints a warning.
Converts category codes to human-readable names for display.
Lowest-Price Identification
Use the
compareTomethod to find and display the product(s) with the lowest price.
Driver Program
Build a
ProductAppdriver to demonstrate:Creating several
Productobjects.Setting and testing passwords.
Locking and unlocking records.
Attempting updates on locked records.
Displaying all products.
Locating and displaying the product(s) with the lowest price.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 54 more lessons in Thompson Rivers University.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.