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

JAVA 1.2 HR

The document outlines an experiment for a project-based learning course in Java, focusing on designing a simple inventory control system for a video rental store. It details the aim, objectives, and procedures for implementing classes such as Video and InventorySystem, along with methods for managing video rentals. The main method demonstrates how to interact with the system using a console interface for adding, renting, and displaying videos.

Uploaded by

fodes88196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

JAVA 1.2 HR

The document outlines an experiment for a project-based learning course in Java, focusing on designing a simple inventory control system for a video rental store. It details the aim, objectives, and procedures for implementing classes such as Video and InventorySystem, along with methods for managing video rentals. The main method demonstrates how to interact with the system using a console interface for adding, renting, and displaying videos.

Uploaded by

fodes88196
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING


Experiment No: 1.2
Student Name: D.Harish UID: 21BCS8540
Branch: CSE Section/Group:21BCS_CC-633/A
Semester: 6th Date of Performance: 17-01-2024
Subject Name: Project Based Learning in Java with Lab
Subject Code: 21CSH-319
• Aim: Design and implement a simple inventory control system for a
small video rental store.
• Objective: To learn about Classes, To learn about
Encapsulation, Aggregation concept in java.
• Input/Apparatus Used: Intellij IDEA
• Procedure/Algorithm/Pseudocode:
• Video Class: Define a class to represent videos with attributes like title, checked
out status, and average user rating.

• VideoStore Class: Create a class to manage videos in a store.


• Include an array to store videos.
• Implement methods to add, check out, return, rate, and list videos.

• Add Video: Add a video to the store by finding the first empty slot in the array
and creating a new Video object.

• Check Out Video: Mark a video as checked out if it's available.

• Return Video: Mark a checked-out video as returned.

• Receive Rating: Update a video's average user rating based on new ratings received.

• List Inventory: Display the details of all videos in the store.

• Main Method:
• Create a VideoStore object.
• Add videos, receive ratings, check out and return videos as needed.
• List the inventory to show the current status.

• Code:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Video {
private String title;
private boolean available;

public Video(String title) {


this.title = title;
this.available = true;
}

public String getTitle() {


return title;
}

public boolean isAvailable() {


return available;
}

public void setAvailable(boolean available) {


this.available = available;
}
}

class Customer {
private String name;

public Customer(String name) {


this.name = name;
}

public String getName() {


return name;
}
}

class InventorySystem {
private List<Video> videos;

public InventorySystem() {
this.videos = new ArrayList<>();
}

public void addVideo(String title) {


videos.add(new Video(title));
System.out.println("Video '" + title + "' added to inventory.");
}

public void rentVideo(String title, Customer customer) {


for (Video video : videos) {
if (video.getTitle().equals(title) && video.isAvailable()) {
video.setAvailable(false);
System.out.println("Video '" + title + "' rented to " + customer.getName());
return;
}
}
System.out.println("Video '" + title + "' not available for rent.");
}

public void displayInventory() {


System.out.println("Current Inventory:");
for (Video video : videos) {
System.out.println("Title: " + video.getTitle() + ", Available: " + (video.isAvailable() ?
"Yes" : "No"));
}
}
}

public class VideoRentalStore {


public static void main(String[] args) {
InventorySystem inventorySystem = new InventorySystem();
Scanner scanner = new Scanner(System.in);

while (true) {
System.out.println("\n1. Add Video\n2. Rent Video\n3. Display Inventory\n4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();

switch (choice) {
case 1:
System.out.print("Enter video title: ");
String title = scanner.next();
inventorySystem.addVideo(title);
break;

case 2:
System.out.print("Enter video title to rent: ");
title = scanner.next();
System.out.print("Enter customer name: ");
String customerName = scanner.next();
Customer customer = new Customer(customerName);
inventorySystem.rentVideo(title, customer);
break;

case 3:
inventorySystem.displayInventory();
break;

case 4:
System.out.println("Exiting the program.");
System.exit(0);

default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
• Result/Output:

You might also like