This is an inventory program that can be used for storing CDs and DVDs. The language used for the program is Object-Oriented Programming, therefore there are 2 classes:
- the driver class: ProductTester, which is in charge of running the object class
- the object class: Product
- 2 subclasses of the Product superclass: DVD and CD
- Adding products to the inventory depending on its type
- Viewing products that are stored
- Add to/Remove from the number of units in stock for a certain product
- Discontinue product sale
- Implementing a user interface: a MENU the user can choose from what changes to apply to the inventory
- Abstraction: the Product class is abstract to avoid creating pure Product objects, only DVD and CD objects are needed.
- Encapsulation: in the Product class the instance fields are declared as private.
- Inheritance: by creating subclasses of the Product class; the DVD and CD subclasses inherit the public methods/getters/setters from the Product parent class, the fields from the superclass are not inherited because they are private, but they can be accessed through the public getters.
- Polymorphism: when creating CD or DVD objects instead of a generic product object; DVD and CD subclasses define their own unique behaviours (overriding methods: getInventoryValue, toString) and yet share some of the same functionality of the Product class. Also, Dynamic Method Dispatch is the mechanism by which a call to an overridden method is resolved at run time, rather than compile time. At run time, it depends on the type of the object being referred to (not the type of the reference variable)
- The use of static methods in the driver class in order to make the code more modular, easier to read and understand
This personal project was inspired by the JF Java Fundamentals Learner course on ORACLE Academy. It was made for learning purposes.
- For compiling the project use command in terminal from the src directory:
javac inventory/ProductTester.java inventory/Product.java - For running the project use command in terminal from the src directory:
java inventory.ProductTester