You are on page 1of 5

Student Name: Ankit Jha UID: 20BCS9637

Branch: BE-CSE Section/Group: 705/A


Semester: 5th Subject: JAVA Lab

Experiment1.2
Aim/Overviewofthepractical:
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 Video Store to model the actual store.

Tasktobedone/Whichlogisticsused:

AssumethatanobjectofclassVideohasthefollowingattributes:
1.A title;
2. aflagtosaywhetheritischeckedoutornot;and3.Anaverageuserrating.

AddinstancevariablesforeachoftheseattributestotheVideoclass.
Inaddition,youwillneedtoaddmethodscorrespondingtothefollowing:
1.beingcheckedout;
2. beingreturned;and 3.receivingarating.

The Video Store class will contain at least an instance variable that references an array
ofvideos(sayoflength10).TheVideoStorewillcontainthefollowingmethods:
1.addVideo(String):addanewvideo(bytitle)totheinventory;
2. checkOut(String):checkoutavideo(bytitle);
3. returnVideo(String): return avideo to thestore;
4. receiveRating(String, int) : take a user's rating for a video; and 5. listInventory(): list
the whole inventory of videos in the store.

Finally, create a Video Store Launcher class with a main() method which will test the
functionality of your other two classes. It should allow the following.
1.Add3videos:"TheMatrix","GodfatherII","StarWarsEpisodeIV:ANewHope".
2. Giveseveralratingstoeachvideo.
3. Renteachvideooutonceandreturnit.

Listtheinventoryafter"GodfatherII" hasbeen rentedout.


Stepsforexperiment/practical/Code:
classVideo{ String
title;
booleanFlag=false; int
avg = 0;
}
classVideoStore{
privatestaticfinalScannerinput=newScanner(System.in); String
chek2;
Videobeat[]=newVideo[10];
intnum_video;
voidaddVideo(){
System.out.println("Enter"+num_video+"VideoTitle:-");
for(inti=0;i<num_video;i++){
beat[i] = new Video();
beat[i].title = input.nextLine();
}
System.out.println("Enter"+num_video+"Videoratingbetween1to5:-");
for(inti=0;i<num_video;i++){ beat[i].avg=
input.nextInt();
}
}
intchekOut(intk){
String chek1;
System.out.println("chekout"+(k+1));
chek1 = input.next();
for(inti=0;i<num_video;i++){
if(beat[i].title.equals(chek1)&&(beat[i].Flag==false)){
beat[i].Flag = true;
return-1;
}
elseif(beat[i].title.equals(chek1)&&(beat[i].Flag==true)){
System.out.println("Failed to chekout: ");
return-1;
}
}
return1;
}
intreturnvideo(intk){
System.out.println("ReturningVideoname:"+(k+1));
chek2 = input.next();
for(inti=0;i<num_video;i++){
if(beat[i].title.equals(chek2)&&beat[i].Flag==true){
System.out.println("Video"+chek2+"isreturned");
this.reciveRating();
beat[i].Flag=false;
return -1;
}
elseif(beat[i].title.equals(chek2)&&beat[i].Flag==false){
System.out.println("U cannot return this!");
return-1;
}
}
return1;
}
voidreciveRating(){
System.out.println("Entertheratingbetween1to5:");
for(inti=0;i<num_video;i++){
if(beat[i].title.equals(chek2)&&beat[i].Flag==true){
beat[i].avg = input.nextInt();
}
}
}
void listInventory() {
System.out.println("ListofallVideos:"); int
total = 0;
for(inti=0;i<num_video;i++){
if (beat[i].Flag== false) {
System.out.println(beat[i].title+"Notchekout");
}else{
System.out.println(beat[i].title+"Chekout!"); total
+= 1;
}
if(beat[i].avg!=0){
System.out.println("Rating:-"+beat[i].avg+"Star");
}
}
System.out.println("Totalnumberofchekoutvideo:"+total);
}
}
publicclassCdSstore{
publicstaticvoidmain(String[]args){
VideoStorebox=newVideoStore();
int chekout;
intret;
Scanner in = new Scanner(System.in);
System.out.println("Numberofvideo:");
box.num_video= in.nextInt();
box.addVideo();
System.out.println("HowManyvideouwantstochekout:0ifudon't");
chekout = in.nextInt();
intchek=1;
intchek1=1;
if(chekout!=0){
for(inti=0;i<chekout;i++){ chek
= box.chekOut(i);
if(chek==1){
System.out.println("VideoNotPresent");
}
}
}
System.out.println("HowManyvideouwantstoReturn:0ifudon't"); ret =
in.nextInt();
if(ret!=0){
for (int i = 0; i< ret; i++)
{ chek1=box.returnvideo(i);
if (chek1 == 1) {

System.out.println("Wornginput!");
}
}
}
box.listInventory();
}
}

Result/Output/WritingSummary:

You might also like