DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.2
Student Name: Manohar Chaudhary UID: 21BCS4422
Branch: BE- CSE Section/Group:21BCS_FL-603-B
th
Semester: 6 Date of Performance:17-01-24
Subject Name: PROJECT BASED LEARNING IN JAVA WITH LAB
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. Algo.
• Start
• Make a class with name Video. In this class make variable related to video.
• Make a class with name VideoStore. In this class functions are made for add video,
rent video, return video. Etc.....
• Make a main class with name VideoStorelauncher. In this class we call all the
function with object of the class.
• End.
4. Code
import java.util.Objects;
import java.util.Scanner;
class Video {
String videoName;
boolean checkout;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int rating;
public Video(String name) {
videoName = name;
}
public String getName() {
return videoName;
}
public void doCheckout() {
System.out.println("Video: \"" + getName() + "\" checked out successfully.");
checkout = true;
}
public boolean getCheckout() {
return checkout; }
public void doReturn() {
checkout = false;
System.out.println("Video: \"" + getName() + "\" returned successfully.");
}
public void receiveRating(int r) {
rating = r;
System.out.println("Video: \"" + getName() + "\" has been rated with " +
getRating() + " stars.");
}
public int getRating() {
return rating;
}
}
class VideoStore {
Video[] videoList;
int count;
public VideoStore() {
videoList = new Video[10];
count = 0;
}
public void addVideo(String name) {
if (count < 10) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
videoList[count++] = new Video(name);
System.out.println("Video: \"" + name + "\" added successfully.");
} else {
System.out.println("Sorry, we can't add more videos. Inventory is full.");
}
}
public void doCheckout(String name) {
for (int j = 0; j < count; j++) {
if (Objects.equals(videoList[j].getName(), name)) {
if (!videoList[j].getCheckout()) {
videoList[j].doCheckout();
} else {
System.out.println("Video: \"" + name + "\" is already checked out.");
}
return;
}
}
System.out.println("Video: \"" + name + "\" not found or already checked out.");
}
public void doReturn(String name) {
for (int j = 0; j < count; j++) {
if (Objects.equals(videoList[j].getName(), name)) {
if (videoList[j].getCheckout()) {
videoList[j].doReturn();
} else {
System.out.println("Video: \"" + name + "\" is not checked out.");
}
return;
}
}
System.out.println("Video: \"" + name + "\" not found or not checked out.");
}
public void receiveRating(String name, int rating) {
for (int j = 0; j < count; j++) {
if (Objects.equals(videoList[j].getName(), name)) {
videoList[j].receiveRating(rating);
return;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
}
System.out.println("Video: \"" + name + "\" not found.");
}
public void listInventory() {
if (count == 0) {
System.out.println("No videos available.");
} else {
System.out.format("%-15s | %-15s | %-10s%n", "Video Name", "Checkout
Status", "Rating");
for (int j = 0; j < count; j++) {
System.out.format("%-15s | %-15b | %-10d%n",
videoList[j].getName(),videoList[j].getCheckout(),videoList[j].getRating());
}
}
}
}
public class VideoStoreLauncher {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
VideoStore videoStore = new VideoStore();
do {
System.out.println("\nOptions:");
System.out.println("1. Add Video");
System.out.println("2. Checkout Video");
System.out.println("3. Return Video");
System.out.println("4. Receive Rating");
System.out.println("5. List Inventory");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
sc.nextLine(); // Consume the newline
switch (choice) {
case 1:
System.out.print("Enter the name of Video to add: ");
videoStore.addVideo(sc.nextLine());
break;
case 2:
System.out.print("Enter the name of Video to checkout: ");
videoStore.doCheckout(sc.nextLine());
break;
case 3:
System.out.print("Enter the name of Video to return: ");
videoStore.doReturn(sc.nextLine());
break;
case 4:
System.out.print("Enter the name of Video to rate: ");
String videoName = sc.nextLine();
System.out.print("Enter rating (1-5): ");
int rating = sc.nextInt();
videoStore.receiveRating(videoName, rating);
break;
case 5:
videoStore.listInventory();
break;
case 6:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
} while (choice != 6);
sc.close();
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
OUTPUT