Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment-1.2
Student Name: Rishi Matura UID: 21BCS9355
Branch: CSE Section/Group: 641 - A
Semester: 6th Date of Performance: 19/01/2024
Subject Name: Java Lab Subject Code: 21CSH-319

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

2. Objective: The goal 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. Finally, create a VideoStoreLauncher class with a main() method
which will test the functionality of your other two classes.

3. Algo. /Approach:

public class Video {


private String title;
private boolean checkedOut;
private double averageUserRating;

public Video(String title) {


this.title = title;
}

public String getTitle() {


return title;
}

public boolean isCheckedOut() {


return checkedOut;
}

public double getAverageUserRating() {


return averageUserRating;
public void checkOut() {
if (!checkedOut) {
checkedOut = true;
System.out.println("Video checked out: " + title);
} else {
System.out.println("Video is already checked out: " + title);
}
}

public void returnVideo() {


if (checkedOut) {
checkedOut = false;
System.out.println("Video returned: " + title);
} else {
System.out.println("Video is not checked out: " + title);
}
}

public void receiveRating(double userRating) {


if (userRating >= 0.0 && userRating <= 10.0) {
averageUserRating = (averageUserRating + userRating) / 2;
System.out.println("Rating received for " + title + ": " + userRating);
} else {
System.out.println("Invalid rating. Please provide a rating between
0.0 and 10.0 for " + title);
}
}
}

public class VideoStore {


private Video[] inventory;

public VideoStore() {
this.inventory = new Video[10];
}

public void addVideo(String title) {


for (int i = 0; i < inventory.length; i++) {
if (inventory[i] == null) {
inventory[i] = new Video(title);
System.out.println("Video added to inventory: " + title);
return;
}
}
System.out.println("Inventory is full. Cannot add video: " + title);
public void checkOut(String title) {
Video video = findVideo(title);
if (video != null) {
video.checkOut();
}
}

public void returnVideo(String title) {


Video video = findVideo(title);
if (video != null) {
video.returnVideo();
}
}

public void receiveRating(String title, double userRating) {


Video video = findVideo(title);
if (video != null) {
video.receiveRating(userRating);
}
}

public void listInventory() {


System.out.println("Inventory:");
for (Video video : inventory) {
if (video != null) {
System.out.println("Title: " + video.getTitle() +
", Checked Out: " + video.isCheckedOut() +
", Average Rating: " + video.getAverageUserRating());
}
}
}

private Video findVideo(String title) {


for (Video video : inventory) {
if (video != null && video.getTitle().equals(title)) {
return video;
}
}
System.out.println("Video not found in inventory: " + title);
return null;
}
}

public class VideoStoreLauncher {


VideoStore videoStore = new VideoStore();
videoStore.addVideo("Inception");
videoStore.addVideo("Pulp Fiction");
videoStore.addVideo("The Shawshank Redemption");
videoStore.receiveRating("Inception", 9.0);
videoStore.receiveRating("Inception", 8.5);
videoStore.receiveRating("Pulp Fiction", 8.0);
videoStore.receiveRating("Pulp Fiction", 9.5);
videoStore.receiveRating("The Shawshank Redemption", 7.0);
videoStore.receiveRating("The Shawshank Redemption", 8.0);
System.out.println("Inventory before renting out 'Pulp Fiction':");
videoStore.listInventory();
videoStore.checkOut("Pulp Fiction");
System.out.println("\nInventory after renting out 'Pulp Fiction':");
videoStore.listInventory();}
}

4. Output:

5.Leatning Outcomes:
I have learnt about :
 how to use methods in java.
 Java classes.
 OOPs programming.

You might also like