0% found this document useful (0 votes)
13 views

JAVA 1.2 suman

The document outlines an experiment for a Computer Science and Engineering course where a simple inventory control system for a video rental store is designed and implemented in Java. It includes the aim, objectives, and code for managing video inventory, ratings, checkouts, and returns. The program utilizes classes, encapsulation, and aggregation concepts in Java.

Uploaded by

suman62033
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)
13 views

JAVA 1.2 suman

The document outlines an experiment for a Computer Science and Engineering course where a simple inventory control system for a video rental store is designed and implemented in Java. It includes the aim, objectives, and code for managing video inventory, ratings, checkouts, and returns. The program utilizes classes, encapsulation, and aggregation concepts in Java.

Uploaded by

suman62033
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/ 7

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.2

Student Name: Suman Kumar UID: 21BCS1276


Branch: CSE Section/Group: CC-605-B
Semester: 6 Date of Performance:19-01-24
Subject Name: JAVA Subject Code: 21CSH-319

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. CODE:

import java.util.HashSet;
import java.util.Scanner;
class Video {
public String title;
public boolean isChecked;
public double rating;
public int numRated;
Video(String title) {
this.title = title;
this.numRated = 0;
this.rating = 0;
this.isChecked = false;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

};
class VideoStore {
Scanner sc = new Scanner(System.in);
public HashSet<Video> inventry = new HashSet<Video>();
public void addVideo(String s) {
Video newVideo = new Video(s);
inventry.add(newVideo);
}
public void addRating(String title) {
System.out.print("Enter a rating between 1 to 10: ");
double rating = sc.nextDouble();
for (Video v : inventry) {
if (v.title.equals(title)) {
double oldrating = v.rating * v.numRated;
v.numRated++;
v.rating = (oldrating + rating) / v.numRated;
break;
}
}
}
public void checkout(String title){
for (Video v : inventry) {
if (v.title.equals(title)) {
v.isChecked = true;
System.out.println(v.isChecked);
break;
}
}
}
public void returnVideo(String title){
for (Video v : inventry) {
if (v.title.equals(title)) {
v.isChecked = false;
break;
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public void showInventry(){


System.out.println("Videos available with us are:- ");
int n = 0;
for(Video v : inventry){
if(v.isChecked==false){
System.out.println(" ");
System.out.println("Title: " + v.title);
System.out.println("Rating: " + v.rating);
System.out.println(" ");
n++;
}
}
if(n==0){
System.out.println("We are out of videos :(");
System.out.println();
}
}
};
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// ArrayList<Video> inventry = new ArrayList<Video>();
VideoStore vidStore = new VideoStore();
while (true) {
System.out.println("Press 1 to add a new Video: ");
System.out.println("Press 2 to add a new rating: ");
System.out.println("Press 3 to checkout a Video: ");
System.out.println("Press 4 to return a Video: ");
System.out.println("Press 5 to check inventry: ");
System.out.println("Press 0 to exit\n");
int key = sc.nextInt();
if (key == 0) {
break;
}
if (key == 1) {
System.out.print("Enter the name of video: ");
String title = sc.next();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

vidStore.addVideo(title);
System.out.println();
}
if (key == 2) {
System.out.print("Enter title of video: ");
String title = sc.next();
vidStore.addRating(title);
System.out.println();
}
if (key == 3) {
System.out.print("Enter title of the video: ");
String title = sc.next();
vidStore.checkout(title);
System.out.println();
}
if (key == 4) {
System.out.print("Enter title of the video: ");
String title = sc.next();
vidStore.returnVideo(title);
System.out.println();
}
if(key==5){
vidStore.showInventry();
System.out.println();
}
}
sc.close();
}

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. OUTPUT:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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