forked from isenmit/javalab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideo.java
More file actions
155 lines (145 loc) · 3.49 KB
/
Video.java
File metadata and controls
155 lines (145 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
public class Video
{
String mName;
boolean status;
double rating;
public Video(String mName, boolean status, double rating)
{
super();
this.mName = mName;
this.status = status;
this.rating = rating;
}
public String getmName()
{
return mName;
}
public void setmName(String mName)
{
this.mName = mName;
}
public boolean isStatus()
{
return status;
}
public void setStatus(boolean status)
{
this.status = status;
}
public double getRating()
{
return rating;
}
public double setRating(double rating)
{
return this.rating = rating;
}
}
Methods Class File : VideoMethods.java
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
public class VideoMethods
{
List<Video> MovieList = new ArrayList<Video>();
public void AddMovies()
{
Scanner in=new Scanner(System.in);
System.out.print("Enter the name of the movie:");
String mName=in.nextLine();
System.out.print("Enter the status of the movie(True/False):");
boolean status=in.nextBoolean();
System.out.print("Enter the ratings for the movie(0-5):");
double rating=in.nextDouble();
Video v=new Video(mName, status, rating);
MovieList.add(v);
System.out.println("Library Initialized");
}
public void DisplayAll()
{
if(MovieList.isEmpty())
{
System.out.println("No movies in the library");
}
for(Video m : MovieList)
{
System.out.println("Movie : " +m.getmName()+" "+"Status : "+m.isStatus()+" "+"Rating "+m.getRating());
}
}
boolean RentOut(String name)
{
for(Video m :MovieList)
{
if(m.getmName().equalsIgnoreCase(name))
{
if(m.isStatus())
{
m.setStatus(false);
return true;
}
}
return false;
}
return false;
}
public void CollectIn(String name,double rat)
{
boolean flag=false;
for(Video m :MovieList)
{
if(m.getmName().equalsIgnoreCase(name))
{
m.setStatus(true);
flag=true;
Math.round(m.setRating((m.getRating() + rat)/2));
}
}
if(!flag)
{
System.out.println("Requested Movie not rented out");
}
}
}
Main Class File: VideoMain.java
import java.util.Scanner;
public class VideoMain
{
public static void main(String args[])
{
VideoMethods mm = new VideoMethods();
while(true)
{
System.out.println("%%%%%%%% VIDEO LIBRARY CENTER %%%%%%%%");
int n;
Scanner in = new Scanner(System.in);
System.out.println("1.ADD MOVIES");
System.out.println("2.DISPLAY MOVIES");
System.out.println("3.RENT OUT");
System.out.println("4.COLLECT BACK ");
System.out.println("PLEASE ENTER YOUR OPTION");
n = in.nextInt();
switch(n)
{
case 1:mm.AddMovies();
break;
case 2:mm.DisplayAll();
break;
case 3:System.out.print("Enter the movie you want to rent.");
in.nextLine();
if(mm.RentOut(in.nextLine()))
{
System.out.println("Rent out successfull");
}
else
{
System.out.println("Sorry!! Not Available");
}
break;
case 4:System.out.println("Enter the name and the ratings of the movie");
in.nextLine();
mm.CollectIn(in.nextLine(),in.nextDouble());
break;
}
}
}
}