Skip to content

Commit 18a63f4

Browse files
committed
Cinema (IPA-35)
1 parent a329a58 commit 18a63f4

2 files changed

Lines changed: 146 additions & 39 deletions

File tree

IPA25.java

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import java.util.*;
2+
public class IPA25 {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
Cinema[] cn = new Cinema[4];
6+
for (int i = 0; i < cn.length; i++) {
7+
int a = sc.nextInt();sc.nextLine();
8+
String b = sc.nextLine();
9+
int c = sc.nextInt();sc.nextLine();
10+
int d = sc.nextInt();sc.nextLine();
11+
12+
cn[i] = new Cinema(a, b, c, d);
13+
}
14+
String dir = sc.nextLine();
15+
int rate = sc.nextInt();sc.nextLine();
16+
int bud = sc.nextInt();sc.nextLine();
17+
18+
int ans1 = findAvgBudgetByDirector(cn,dir);
19+
if(ans1!=0)
20+
{
21+
System.out.println(ans1);
22+
}
23+
else{
24+
System.out.println("Sorry - The given director has not yet directed any movie");
25+
}
26+
27+
int ans2 = getMovieByRatingBudget(cn, rate, bud);
28+
if(ans2!=0)
29+
{
30+
System.out.println(ans2);
31+
}
32+
else
33+
{
34+
System.out.println("Sorry - No movie is available with the specified rating and budget requirement");
35+
}
36+
}
37+
public static int findAvgBudgetByDirector(Cinema[] cn, String dir)
38+
{
39+
int sum = 0, count = 0;
40+
for (int i = 0; i < cn.length; i++) {
41+
if(cn[i].getDirector().equalsIgnoreCase(dir))
42+
{
43+
sum += cn[i].getBudget();
44+
count++;
45+
}
46+
}
47+
if(count>0)
48+
{
49+
int avg = sum/count;
50+
return avg;
51+
}
52+
else
53+
{
54+
return 0;
55+
}
56+
}
57+
public static int getMovieByRatingBudget(Cinema[] cn, int r, int b)
58+
{
59+
for (int i = 0; i < cn.length; i++) {
60+
if(cn[i].getBudget()==b && cn[i].getRating()==r && b%r==0)
61+
{
62+
return cn[i].getId();
63+
}
64+
}
65+
return 0;
66+
}
67+
}
68+
class Cinema
69+
{
70+
private int id;
71+
private String director;
72+
private int rating, budget;
73+
74+
public Cinema(int id, String director, int rating, int budget) {
75+
this.id = id;
76+
this.director = director;
77+
this.rating = rating;
78+
this.budget = budget;
79+
}
80+
public int getId() {
81+
return id;
82+
}
83+
public void setId(int id) {
84+
this.id = id;
85+
}
86+
public String getDirector() {
87+
return director;
88+
}
89+
public void setDirector(String director) {
90+
this.director = director;
91+
}
92+
public int getRating() {
93+
return rating;
94+
}
95+
public void setRating(int rating) {
96+
this.rating = rating;
97+
}
98+
public int getBudget() {
99+
return budget;
100+
}
101+
public void setBudget(int budget) {
102+
this.budget = budget;
103+
}
104+
105+
106+
}

IPA25.txt

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
## Problem Statement
1+
Create a class Cinema with the below attributes:
22

3-
Create a class Movie with the below attributes:
43
movieId - int
54
director - String
65
rating - int
@@ -13,13 +12,16 @@ Create class Solution with the main method.
1312
Implement two static methods - findAvgBudgetByDirector and getMovieByRatingBudget in Solution class.
1413

1514
findAvgBudgetByDirector method:
15+
----------------------------------
1616
This method will take two input parameters - array of Movie objects and string parameter director.
1717
The method will return the average of the budget attribute from Movie objects directed by the director passed as parameter.
1818
If no movie with the given director is present in the array of movie objects, then the method should return 0.
1919

2020
getMovieByRatingBudget method:
21+
----------------------------------
2122
This method will take two int parameters rating and budget, along with the array of movie objects.
22-
The method will return the movie object, if the input parameters rating and budget, matches with the rating and budget attribute of the movie object respectively.
23+
The method will return the movie object, if the input parameters rating and budget, matches with the rating and budget
24+
attribute of the movie object respectively.
2325

2426
Also check if rating is a factor of budget (eg: 3 is a factor of 12 because 3 divides 12 without leaving a remainder).
2527
If any of the conditions are not met, then the method should return null.
@@ -30,39 +32,38 @@ The budget mentioned are in crores and in INR.
3032

3133
These above mentioned static methods should be called from the main method.
3234

33-
For findAvgBudgetByDirector method - The main method should print the average budget as it is if the returned value is greater than 0, or it
34-
should print "Sorry - The given director has not yet directed any movie".
35-
36-
For getMovieByRatingBudget method - The main method should print the movieId of the returned movie object. If the returned value is null
37-
then it should print "Sorry - No movie is available with the specified rating and budget requirement".
38-
39-
Before calling these static methods in main, use Scanner object to read the values of four
40-
Movie objects referring attributes in the above mentioned attribute sequence.
41-
Next, read the value for director, rating and budget.
42-
43-
## Input
44-
45-
1101
46-
GVM
47-
4
48-
100
49-
1201
50-
Shankar
51-
5
52-
500
53-
1301
54-
Shankar
55-
3
56-
50
57-
1401
58-
GVM
59-
5
60-
300
61-
GVM
62-
5
63-
300
64-
65-
## Output
66-
67-
200
68-
1401
35+
For findAvgBudgetByDirector method - The main method should print the average budget as it is if the returned value is
36+
greater than 0, or it should print "Sorry - The given director has not yet directed any movie".
37+
38+
For getMovieByRatingBudget method - The main method should print the movieId of the returned movie object. If the returned
39+
value is null then it should print "Sorry - No movie is available with the specified rating and budget requirement".
40+
41+
Before calling these static methods in main, use Scanner object to read the values of four Movie objects referring attributes
42+
in the above mentioned attribute sequence. Next, read the value for director, rating and budget.
43+
44+
Input
45+
----------
46+
1101
47+
GVM
48+
4
49+
100
50+
1201
51+
Shankar
52+
5
53+
500
54+
1301
55+
Shankar
56+
3
57+
50
58+
1401
59+
GVM
60+
5
61+
300
62+
GVM
63+
5
64+
300
65+
66+
Output
67+
----------
68+
200
69+
1401

0 commit comments

Comments
 (0)