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

HiteshJavaexp 1.2

This document describes an experiment to design and implement a simple video rental inventory system in Java. It defines two classes - Video to model individual videos and their attributes like title and checkout status, and VideoStore to model the overall store and inventory. A VideoStoreLauncher class is used to test the system by adding videos to the inventory, receiving user ratings, checking a video out and listing the current inventory. The output shows the inventory status before and after a video is checked out.

Uploaded by

Amaan Amaan
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)
20 views4 pages

HiteshJavaexp 1.2

This document describes an experiment to design and implement a simple video rental inventory system in Java. It defines two classes - Video to model individual videos and their attributes like title and checkout status, and VideoStore to model the overall store and inventory. A VideoStoreLauncher class is used to test the system by adding videos to the inventory, receiving user ratings, checking a video out and listing the current inventory. The output shows the inventory status before and after a video is checked out.

Uploaded by

Amaan Amaan
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
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment-1.2
Student Name: Hitesh Rao UID: 21BCS8322
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("The Matrix");
videoStore.addVideo("Godfather III");
videoStore.addVideo("Star Wars Episode IV: A New Hope");

videoStore.receiveRating("The Matrix", 8.5);


videoStore.receiveRating("The Matrix", 9.0);
videoStore.receiveRating("Godfather III", 9.5);
videoStore.receiveRating("Godfather III", 8.0);
videoStore.receiveRating("Star Wars Episode IV: A New Hope", 7.5);
videoStore.receiveRating("Star Wars Episode IV: A New Hope", 8.5);

System.out.println("Inventory before renting out 'Godfather III':");


videoStore.listInventory();

videoStore.checkOut("Godfather III");

System.out.println("\nInventory after renting out 'Godfather III':");


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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy