Java Video Rental System Project
Java Video Rental System Project
Method abstraction is utilized in both Video and VideoStore classes by defining clear, task-specific methods like checkOut(), returnVideo(), addVideo(), and listInventory(), each responsible for a unit operation of the system. This abstraction allows users to interact with the objects without needing to understand internal logic details, simplifying usage and interaction. It aids in maintaining code organization, readability, and reusability, critical for scalable application development .
The development of Video and VideoStore classes reinforces concepts such as object-oriented programming, encapsulation, method abstraction, and encapsulated data management through private instance variables and public methods. It demonstrates practical handling of arrays for data storage, interaction of multiple classes, and maintaining object states with methods that reflect real-world operations. These concepts are fundamental and can be applied broadly for designing scalable, modular, and maintainable software systems with clear interfaces and controlled inter-object interactions .
The VideoStoreLauncher class tests the functionality of the video rental system by creating an instance of the VideoStore and sequentially performing key operations that mimic real-world use. It adds three videos, receives user ratings for each, checks out and returns a video, and finally lists all videos to verify states and data consistency. This comprehensive sequence ensures the methods of Video and VideoStore are functioning correctly through a controlled series of interactions, demonstrating end-to-end testing .
The Video class uses the receiveRating method to handle user inputs for video ratings. This method checks the validity of the rating, ensuring it falls between 1 and 5, and then calculates a new average rating using a running total method based on inputs over time, while updating the rating count. This design implies the use of double for averageRating and int for ratingCount to maintain numerical precision and enable dynamic recalculation as new ratings are added .
The use of arrays in the VideoStore class allows for efficient storage and management of a fixed number of Video objects, facilitating quick access and updates. Arrays enable direct index-based retrieval and updates, crucial for the operations of adding, checking out, and returning videos. This constant-size data structure aligns with the fixed inventory model, simplifying memory management and ensuring predictable performance, though it lacks dynamic resizing, which could limit scalability .
Encapsulation in the Video class is achieved by declaring instance variables like title, checkedOut, and averageRating as private, ensuring that they cannot be accessed directly from outside the class. The class provides public methods such as getTitle(), isCheckedOut(), and getAverageRating() to allow controlled access to their values. This hides the internal state of objects and only exposes necessary parts of the class interface, promoting modularity and security .
In the receiveRating method, input validation is handled by checking if the provided rating is between 1 and 5. If the rating doesn't meet these criteria, an error message is displayed, and the method exits without modifying the video’s average rating. This mechanism contributes to the system's robustness by preventing the corruption of data due to invalid inputs, ensuring consistent, expected operation under various user interactions .
To improve scalability and flexibility in real-world applications, replacing the fixed-size array with a dynamic data structure like an ArrayList could be suggested. ArrayLists can automatically resize as elements are added or removed, thus accommodating varying inventory sizes more effectively. Additionally, implementing a hashmap could enhance search efficiency, allowing constant-time complexity for lookups via title keys. Enhancing storage with these data structures ensures the system can scale without bounds and handle more complex operations efficiently .
The checkOut method sets the checkedOut attribute of a Video object to true, indicating that the video is rented out, and prints a confirmation message. If the video is already checked out, it notifies that the action can't be performed. The returnVideo method sets the checkedOut attribute to false, indicating that the video has been returned, and also prints a confirmation message. It checks the current status and notifies if the video was not rented out .
The VideoStore class manages a limited inventory by using an array to store Video objects with a fixed capacity defined at the instantiation of a VideoStore object. The class includes methods addVideo(String) to add new videos, checkOut(String) to rent out a video, returnVideo(String) to return a video, and listInventory() to list all videos. It also uses findVideo(String) to locate specific videos in its inventory. The addVideo method checks if there is room in the array before adding new videos, preventing overflow by issuing a message if the array is full .