-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.java
More file actions
277 lines (264 loc) · 11.8 KB
/
Functions.java
File metadata and controls
277 lines (264 loc) · 11.8 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Functions extends project_main{
public static void search_by_Title(){
System.out.println("Please enter the movie title:");
int temp = 0;
Scanner scn3 = new Scanner(System.in);
String str= scn3.nextLine();
for (Movie s : movieList) {
if (s.getMovie_name().equals(str)) {
temp = 1;
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
}
}
if (temp == 0) {
System.out.println("No such movie with this name");
}
}
public static void search_by_year(){
System.out.println("Please enter Releasing year of movie:");
Scanner scn3 = new Scanner(System.in);
int i= scn3.nextInt();
int temp = 0;
for (Movie s : movieList) {
if (s.getReleasing_year() == i) {
temp = 1;
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
}
}
if (temp == 0) {
System.out.println("No such movie with this release year");
}
}
public static void search_by_genre(){
System.out.println("Please enter Genre of the movie:");
Scanner scn3 = new Scanner(System.in);
String str= scn3.nextLine();
int temp = 0;
for (Movie s : movieList) {
if (s.getGenre1().equals(str) || s.getGenre2().equals(str) || s.getGenre3().equals(str)) {
temp = 1;
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
}
}
if (temp == 0) {
System.out.println("“No such movie with this genre");
}
}
public static void search_by_company() {
System.out.println("Please enter Production company of movie:");
Scanner scn3 = new Scanner(System.in);
String str = scn3.nextLine();
int temp = 0;
for (Movie s : movieList) {
if (s.getCompany().equals(str)) {
temp = 1;
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
}
}
if (temp == 0) {
System.out.println("No such movie with this production company");
}
}
public static void search_by_running_time(){
System.out.println("Please enter the range of Running Time of movie:");
Scanner scn3 = new Scanner(System.in);
int temp = 0, low = scn3.nextInt(), high = scn3.nextInt();
for (Movie s : movieList) {
if (low <= s.getRunning_time() && s.getRunning_time() <= high) {
temp = 1;
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
}
}
if (temp == 0) {
System.out.println("No such movie with this running time range");
}
}
public static void top_10_movies() {
List<Movie> movieList2 = new ArrayList<>(movieList);
double[] index_array = new double[movieList2.size()];
for (int i = 0; i < movieList2.size(); i++) {
index_array[i] = movieList2.get(i).getRevenue() - movieList2.get(i).getBudget();
}
for (int i = 0; i < index_array.length - 1; i++) {
for (int j = i + 1; j < index_array.length; j++) {
if (index_array[i] < index_array[j]) {
double t = index_array[i];
index_array[i] = index_array[j];
index_array[j] = t;
}
}
}
for (int i = 0; i < 10; i++) {
for (int j = 0; j < movieList2.size(); j++) {
if (index_array[i] == movieList2.get(j).getRevenue() - movieList2.get(j).getBudget()) {
Movie s = movieList2.get(j);
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
movieList2.remove(j);
}
}
}
}
public static void company_recent_movies(){
System.out.println("Please input a production company:");
Scanner scn3 = new Scanner(System.in);
String str= scn3.nextLine();
int temp=0;
List<Movie> movieList2 = new ArrayList();
for (Movie s : movieList) {
if (s.getCompany().equals(str)) {
temp=1;
movieList2.add(s);
}
}
if(temp!=0){
int[] index_array = new int[movieList2.size()];
for (int i = 0; i < movieList2.size(); i++) {
index_array[i] = movieList2.get(i).getReleasing_year();
}
for (int i = 0; i < index_array.length - 1; i++) {
for (int j = i + 1; j < index_array.length; j++) {
if (index_array[i] < index_array[j]) {
int t = index_array[i];
index_array[i] = index_array[j];
index_array[j] = t;
}
}
}
for (int i = 0; i <index_array.length; i++) {
for (int j = 0; j < movieList2.size(); j++) {
if (index_array[i] == movieList2.get(j).getReleasing_year()) {
Movie s = movieList2.get(j);
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
movieList2.remove(j);
}
}
}}
if(temp==0) System.out.println("No such production company with this name");
}
public static void company_maximum_revenue_movies(){
System.out.println("Please input a production company:");
Scanner scn3 = new Scanner(System.in);
String str= scn3.nextLine();
List<Movie> movieList2 = new ArrayList();
for (Movie s : movieList) {
if (s.getCompany().equals(str)) {
movieList2.add(s);
}
}
if(movieList2.size()>0){
long[] index_array = new long[movieList2.size()];
for (int i = 0; i < movieList2.size(); i++) {
index_array[i] = movieList2.get(i).getRevenue();
}
for (int i = 0; i < index_array.length - 1; i++) {
for (int j = i + 1; j < index_array.length; j++) {
if (index_array[i] < index_array[j]) {
long t = index_array[i];
index_array[i] = index_array[j];
index_array[j] = t;
}
}
}
for (int i = 0; i <index_array.length; i++) {
for (int j = 0; j < movieList2.size(); j++) {
if (index_array[i] == movieList2.get(j).getRevenue()) {
Movie s = movieList2.get(j);
System.out.println(s.getMovie_name() + " " + s.getReleasing_year() + " " + s.getGenre1() + " " + s.getGenre2() + " " + s.getGenre3() + " " + s.getRunning_time() + " " + s.getCompany() + " " + s.getBudget() + " " + s.getRevenue());
movieList2.remove(j);
}
}
}}
else System.out.println("No such production company with this name");
}
public static void company_total_profit(){
System.out.println("Please input a production company:");
Scanner scn3 = new Scanner(System.in);
String str= scn3.nextLine();
List<Movie> movieList2 = new ArrayList();
for (Movie s : movieList) {
if (s.getCompany().equals(str)) {
movieList2.add(s);
}
}
if(movieList2.size()>0){
double total_profit=0;
for (Movie s : movieList2) {
total_profit+=s.getRevenue()-s.getBudget();
}
System.out.println("Total Profit:"+total_profit);
}
else System.out.println("No such production company with this name");
}
public static void all_company_and_movies_count(){
List<String> company_list= new ArrayList();
company_list.add(movieList.get(1).getCompany());
for (int i = 0; i < movieList.size(); i++) {
String temp_name= movieList.get(i).getCompany();
for (int j =0 ; j < company_list.size(); j++) {
int ch=0;
for (String s:company_list) {
if(s.equals(temp_name)) ch++;
}
if(ch==0) {
company_list.add(temp_name);
}
}
}
for (int i = 0; i <company_list.size(); i++) {
String temp_name = company_list.get(i);
int count=0;
for (int j=0; j<movieList.size(); j++) {
if (movieList.get(j).getCompany().equals(temp_name)) {
count++;
}
}
System.out.println(temp_name + ", Total Number of Movies:" + count);
}
/*for (int i = 0; i <company_list.size(); i++) {
String temp_name = company_list.get(i);
int count=0;
for (String s:company_list){
if (s.equals(temp_name)) count++;
}
System.out.println(temp_name +" "+ count);
}*/
}
public static void add_new_movie_in_database(){
Movie temp_movie_for_add =new Movie();
System.out.println("Please Enter the Movie Name:");
Scanner add_scn = new Scanner(System.in);
String str= add_scn.nextLine();
temp_movie_for_add.setMovie_name(str);
System.out.println("Please Enter Releasing year:");
add_scn= new Scanner(System.in);
double temp_var=add_scn.nextInt();
temp_movie_for_add.setReleasing_year((int) temp_var);
System.out.println("Please Enter Running Time:");
add_scn= new Scanner(System.in);
temp_var=add_scn.nextInt();
temp_movie_for_add.setRunning_time((int) temp_var);
System.out.println("Please Enter Maximum three genre of the Movie(comma(\",\") separated):");
add_scn=new Scanner(System.in);
String Genre = add_scn.nextLine();
String[] split_genre=Genre.split(",");
temp_movie_for_add.setGenre1(split_genre[0]);
temp_movie_for_add.setGenre2(split_genre[1]);
temp_movie_for_add.setGenre3(split_genre[2]);
System.out.println("Please Enter the Company Name:");
add_scn=new Scanner(System.in);
str= add_scn.nextLine();
temp_movie_for_add.setCompany(str);
System.out.println("Please Enter Budget of the Movie:");
add_scn= new Scanner(System.in);
temp_var=add_scn.nextInt();
temp_movie_for_add.setBudget((int) temp_var);
System.out.println("Please Enter Revenue of the Movie:");
add_scn= new Scanner(System.in);
temp_var=add_scn.nextInt();
temp_movie_for_add.setRevenue((int) temp_var);
movieList.add(temp_movie_for_add);
}
}