CJCoding With Joseph
15free / daySign inCreate account

Thompson Rivers University

Assignment Overview: Polymorphism & Interfaces

Assignment 2 Product - SM 2025

This 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:

  1. Product Data Management

    • Each product record stores a code, description, price, and category.

    • Categories include UNCLASSIFIED plus three user-defined types (e.g., MEAT, DAIRY, PRODUCE).

  2. 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.

  3. Interface Design

    • Category interface: declares integer category constants and methods to set/get a product’s category.

    • PasswordLockable interface: 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.

  4. Class Implementation

    • Create a Product class 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.

  5. Lowest-Price Identification

    • Use the compareTo method to find and display the product(s) with the lowest price.

  6. Driver Program

    • Build a ProductApp driver to demonstrate:

      • Creating several Product objects.

      • 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.

Members only

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.