We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
ll
CHANDIGARH
UNIVERSITY
Experiment1.2
Student Name:Shveta Rattanpal UID: 22BCS80279
Branch:BE-CSE Section/Group:21BCS_CC_635/A
Semester: 6 Date of Performance:
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
3. Algo. /Approach and output:
class Video {
private String title;
private boolean checkedOut;
private double averageRating;
private int numberOfRatings;
public Video(String title) {
this.title = ttle;
this.checkedOut = false;
this.averageRating ~ 0.0;
this numberOfRatings = 0;
}
public String getTitleQ {
retum title;om CHANDIGARH
‘ia UNIVERSITY
‘over. Learn, Empower,
public boolean isCheckedOut() {
retum checkedOut;
t
public void checkOut() {
checkedOut = true;
i
public void returnVideo() {
checkedOut = false;
+
public void receiveRating(int rating) {
averageRating = (averageRating * numberOfRatings + rating) / (numberOfRatings +
Ds
numberOfRatings++;
i
public double getAverageRating() {
return averageRating;
i
class VideoStore {
private Video[] inventory;
public VideoStoreQ) {
this inventory ~ new Video[ 10];
t
public void addVideo(String title) {
for (int i= 0; i< inventory.length; i++) {
if (inventory[i] = null) {
inventory[i] = new Video(title);
‘System.out.printin(""Video " + title + " added to the inventory.");om CHANDIGARH
‘ia UNIVERSITY
‘over. Learn, Empower,
return;
t
System. out printIn("Error: Inventory is full, Cannot add video " + title +".");
+
public void checkOut(String title) {
for (Video video : inventory) {
if (video != null && video. getTitle().cquals(title) && Wvideo.isCheckedOut()) {
video.checkOut(;
System. out printin("Video " + title +" checked out.");
return;
}
System.out println("Error: Video " + title + " not found or already checked out.");
t
public void returnVideo(String title) {
for (Video video : inventory) {
if (video != null && video.getTitle().equals(title) && video.isCheckedOut() {
video.returnVideo();
System.out printin("Video " + title +" retuned.");
return;
}
System.out.printn("Error: Video " + title +" not found or not checked out,
}
public void receiveRating(String title, int rating) {
for (Video video : inventory) {
if (video != null && video. getTitle().equals(title)) {om CHANDIGARH
‘ia UNIVERSITY
‘over. Learn, Empower,
video receiveRating(rating);
System.out.printin("Rating of " + rating +" received for video" + title +"'.");
return;
}
+
System.out printin("Error: Video " + title +" not found.");
t
public void listInventory() {
System.out.printIn("Current Inventory");
for (Video video : inventory) {
if (video != null) {
System.out.printin("Title: " + video getTitle() +
", Checked Out: " + video.isCheckedOut() +
", Average Rating: " + video.getAverageRating());
i
public class VideoStoreLauncher {
public static void main(String{] args) {
VideoStore videoStore = new VideoStore();
videoStore.addVideo("The Matrix");
videoStore.addVideo("Godfather II");
videoStore.addVideo("Star Wars Episode IV: A New Hope");
videoStore.receiveRating("The Matrix”, 4);
videoStore.receiveRating("The Matrix", 5);
ideoStore.receiveRating("Godfather II", 5);
videoStore.receiveRating("Godfather II", 4);om CHANDIGARH
‘ia UNIVERSITY
videoStore.receiveRating("Star Wars Episode IV: A New Hop.
videoStore.checkOut("The Matrix");
videoStore.retumnVideo("The Matrix");
videoStore.checkOut("Godfather II");
videoStore.returnVideo(" Godfather II");
leoStore.checkOut("Star Wars Episode IV: A New Hope");
videoStore.retumVideo(""Star Wars Episode IV: A New Hope");
videoStore.listInventory();