0% found this document useful (0 votes)
6 views4 pages

Java Video Rental System Project

kjbdhesdnmbm jxvcysdgbfvi ijgvciusdgvb s

Uploaded by

sumitsingla271
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)
6 views4 pages

Java Video Rental System Project

kjbdhesdnmbm jxvcysdgbfvi ijgvciusdgvb s

Uploaded by

sumitsingla271
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

Experiment- 1.

Student Name: Sumit UID: 21BCS10075


Branch: BE-CSE Section/Group: KRG_SC_1
Semester: 6th Date of Performance: 17/01/2024
Subject Name: Project Based Learning in Java Subject Code: 21CSH-319

1. Aim: Design and implement a simple inventory control system for a small video
rental store.

2. Objective:
• To learn about Classes.
• To learn about Encapsulation, Aggregation concept in java.

3. Script and Output:


class Video {
private String title;
private boolean checkedOut;
private double averageRating;
private int numberOfRatings;
public Video(String title) {
[Link] = title;
[Link] = false;
[Link] = 0.0;
[Link] = 0;
}
public String getTitle() {
return title;
}
public boolean isCheckedOut() {
return checkedOut;
}
public void checkOut() {
checkedOut = true;
}
public void returnVideo() {
checkedOut = false;
}
public void receiveRating(int rating) {
averageRating = (averageRating * numberOfRatings + rating) / (numberOfRatings + 1);
numberOfRatings++;
}
public double getAverageRating() {
return averageRating;
}
}
class VideoStore {
private Video[] inventory;
public VideoStore() {
[Link] = new Video[10];
}
public void addVideo(String title) {
for (int i = 0; i < [Link]; i++) {
if (inventory[i] == null) {
inventory[i] = new Video(title);
[Link]("Video '" + title + "' added to the inventory.");
return;
}
}
[Link]("Error: Inventory is full. Cannot add video '" + title + "'.");
}
public void checkOut(String title) {
for (Video video : inventory) {
if (video != null && [Link]().equals(title) && ![Link]()) {
[Link]();
[Link]("Video '" + title + "' checked out.");
return;
}
}
[Link]("Error: Video '" + title + "' not found or already checked out.");
}
public void returnVideo(String title) {
for (Video video : inventory) {
if (video != null && [Link]().equals(title) && [Link]()) {
[Link]();
[Link]("Video '" + title + "' returned.");
return;
}
}
[Link]("Error: Video '" + title + "' not found or not checked out.");
}
public void receiveRating(String title, int rating) {
for (Video video : inventory) {
if (video != null && [Link]().equals(title)) {
[Link](rating);
[Link]("Rating of " + rating + " received for video '" + title + "'.");
return;
}
}
[Link]("Error: Video '" + title + "' not found.");
}
public void listInventory() {
[Link]("Current Inventory:");
for (Video video : inventory) {
if (video != null) {
[Link]("Title: " + [Link]() +
", Checked Out: " + [Link]() +
", Average Rating: " + [Link]());
}
}
}
}
public class Main {
public static void main(String[] args) {
VideoStore videoStore = new VideoStore();
[Link]("The Matrix");
[Link]("Godfather II");
[Link]("Star Wars Episode IV: A New Hope");
[Link]("The Matrix", 4);
[Link]("The Matrix", 5);
[Link]("Godfather II", 5);
[Link]("Godfather II", 4);
[Link]("Star Wars Episode IV: A New Hope", 3);
[Link]("The Matrix");
[Link]("The Matrix");
[Link]("Godfather II");
[Link]("Godfather II");
[Link]("Star Wars Episode IV: A New Hope");
[Link]("Star Wars Episode IV: A New Hope");
[Link]();
}
}
Output:

Fig 1: Output of Video Rental System

Common questions

Powered by AI

Encapsulation enhances the design by restricting direct access to video attributes; it provides public methods like getTitle(), checkOut(), and returnVideo() for controlled manipulation, ensuring data integrity and reducing errors from unauthorized access.

Improvements could include dynamic inventory management using data structures like ArrayList for flexible size adjustment, implementing persistent storage for data retrieval after restarts, and adding user management capabilities to handle multiple customers and transactions for scalability and improved business operations.

Aggregation plays a crucial role as the VideoStore class contains an array of Video objects. This signifies a whole-part relationship, allowing VideoStore to manage and access each individual Video, which streamlines operations like adding, rating, and checking out videos, thus ensuring organized interaction with the inventory.

The system handles errors by checking conditions before making state changes, such as whether inventory is full before adding new videos, or whether a video is already checked out before proceeding. Error messages are displayed when constraints are violated. While this provides feedback, the lack of dynamic inventory scaling and more detailed error handling limits effectiveness.

The concept of a 'class' is implemented through the Video class which encapsulates properties such as title, checkedOut status, and averageRating. It includes methods for checking out, returning, and rating the video, encapsulating the data and behaviors related to video items within one unit.

Average ratings are calculated using a cumulative average formula. When a new rating is received, it updates the averageRating by multiplying the current average by the number of ratings, adding the new rating, and dividing by the incremented number of ratings. This maintains an accurate running average.

The system uses a boolean field `checkedOut` in the Video class, toggled by checkOut() and returnVideo() methods, to manage the checked-out status. This approach ensures that videos cannot be checked out multiple times or returned without being checked out first, improving user experience by maintaining accurate transactional records.

The system ensures integrity and accuracy by updating average ratings through a formula that considers previous ratings and the number of times the video has been rated. Methods enforce structured access to modify ratings, preventing direct and erroneous manipulations, and ensure correct calculations are followed.

The primary objectives are to learn about classes, encapsulation, and the aggregation concept in Java.

The system limits inventory to 10 videos, potentially leading to issues where new entries cannot be added if all slots are filled, as indicated by error messages. This constraint may prevent the store’s inventory from scaling with business growth, affecting service delivery and customer satisfaction.

You might also like