0% found this document useful (0 votes)
8 views7 pages

Java Video Rental System Project

The document outlines a project for creating a simple inventory control system for a video rental store using Java. It details the design of two classes, Video and VideoStore, along with their attributes and methods, and includes a VideoStoreLauncher class to test the functionality. The project aims to enhance understanding of object-oriented programming concepts and practical application of Java programming.

Uploaded by

sumit kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Java Video Rental System Project

The document outlines a project for creating a simple inventory control system for a video rental store using Java. It details the design of two classes, Video and VideoStore, along with their attributes and methods, and includes a VideoStoreLauncher class to test the functionality. The project aims to enhance understanding of object-oriented programming concepts and practical application of Java programming.

Uploaded by

sumit kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 2
Student Name: SUMIT KUMAR UID:22BCS12284
Branch: BE-CSE Section/Group:636 B
Semester:6 th Date of Performance:
Subject Name: Project Based Learning Subject Code: 22CSH-359
in Java with Lab

1. Aim: The aim of this project is to design and implement a simple inventory
control system for a small video rental store. Define least two classes: a class
Video to model a video and a class VideoStore to model the

actual store.

Assume that an object of class Video has the following attributes:

1. A title;
2. a flag to say whether it is checked out or not;
3. An average user rating.

Add instance variables for each of these attributes to the Video class.

In addition, you will need to add methods corresponding to the following:

1. being checked out;


2. being returned;
3. receiving a rating.

The VideoStore class will contain at least an instance variable that references an
array of videos (say of length 10). The VideoStore will contain the following
methods:

1. addVideo(String): add a new video (by title) to the inventory;


2. checkOut(String): check out a video (by title);
3. returnVideo(String): return a video to the store;
4. receiveRating(String, int) : take a user's rating for a video; and 5.
listInventory(): list the whole inventory of videos in the store.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. Objective: Create a VideoStoreLauncher class with a main() method which will


test the functionality of your other two classes. It should allow the following.

1. Add 3 videos: "The Matrix", "Godfather II", "Star Wars Episode IV: A New
Hope".
2. Give several ratings to each video.
3. Rent each video out once and return it.

List the inventory after "Godfather II" has been rented out.

3. Implementation/Code:

1. Video Class:-
class Video {
private String title;
private boolean checkedOut;
private double averageRating;
private int ratingCount;

public Video(String title) {


[Link] = title;
[Link] = false;
[Link] = 0.0;
[Link] = 0;
}

public void checkOut() {


if (!checkedOut) {
checkedOut = true;
[Link]("Video \"" + title + "\" has been checked out.");
} else {
[Link]("Video \"" + title + "\" is already checked out.");
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void returnVideo() {


if (checkedOut) {
checkedOut = false;
[Link]("Video \"" + title + "\" has been returned.");
} else {
[Link]("Video \"" + title + "\" was not checked out.");
}
}

public void receiveRating(int rating) {


if (rating < 1 || rating > 5) {
[Link]("Invalid rating. Please rate between 1 and 5.");
return;
}
averageRating = (averageRating * ratingCount + rating) /
(++ratingCount);
[Link]("Received rating of " + rating + " for video \"" + title +
"\".");
}

public String getTitle() {


return title;
}

public boolean isCheckedOut() {


return checkedOut;
}

public double getAverageRating() {


return averageRating;
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. VideoStore Class:-
class VideoStore {
private Video[] videos;
private int count;

public VideoStore(int capacity) {


videos = new Video[capacity];
count = 0;
}

public void addVideo(String title) {


if (count < [Link]) {
videos[count++] = new Video(title);
[Link]("Added video: " + title);
} else {
[Link]("Inventory is full. Cannot add more videos.");
}
}

public void checkOut(String title) {


Video video = findVideo(title);
if (video != null) {
[Link]();
} else {
[Link]("Video \"" + title + "\" not found.");
}
}

public void returnVideo(String title) {


Video video = findVideo(title);
if (video != null) {
[Link]();
} else {
[Link]("Video \"" + title + "\" not found.");
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void receiveRating(String title, int rating) {


Video video = findVideo(title);
if (video != null) {
[Link](rating);
} else {
[Link]("Video \"" + title + "\" not found.");
}
}

public void listInventory() {


[Link]("\nInventory:");
for (int i = 0; i < count; i++) {
Video video = videos[i];
[Link]("Title: " + [Link]() + ", Checked Out: " +
[Link]() +
", Average Rating: " + [Link]());
}
}

private Video findVideo(String title) {


for (int i = 0; i < count; i++) {
if (videos[i].getTitle().equalsIgnoreCase(title)) {
return videos[i];
}
}
return null;
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

3. VideoStoreLauncher Class:-
public class VideoStoreLauncher {
public static void main(String[] args) {
VideoStore store = new VideoStore(10);

[Link]("The Matrix");
[Link]("Godfather II");
[Link]("Star Wars Episode IV: A New Hope");

[Link]("The Matrix", 5);


[Link]("Godfather II", 4);
[Link]("Star Wars Episode IV: A New Hope", 5);

[Link]("Godfather II");
[Link]("Godfather II");

[Link]();
}
}
4. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

5. Learning Outcomes:
1. Designed a functional system to manage video rentals, demonstrating the use
of classes and objects in Java.
2. Implemented methods for operations like adding videos, renting out, returning,
and recording user ratings.
3. Applied arrays to store and efficiently manage the video inventory within the
store.
4. Learned to integrate multiple classes and enable seamless interaction among
them in a structured program.
5. Strengthened understanding of object-oriented programming concepts like
encapsulation and method abstraction.

Common questions

Powered by AI

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 .

You might also like