Java Movie Management
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
Movie[] mv = new Movie[4];
for(int i=0;i<4;i++)
{
int a = sc.nextInt();sc.nextLine();
String b = sc.nextLine();
int c = sc.nextInt();
int d = sc.nextInt();
mv[i] = new Movie(a,b,c,d);
}
sc.nextLine();
String nm = sc.nextLine();
int um = sc.nextInt();
int dm = sc.nextInt();
int res = findAvgBudgetByDirector(mv, nm);
if (res>0)
System.out.println(res);
else
System.out.println("Sorry - The given director has not yet directed any movie");
Movie temp = getMovieByRatingBudget(mv, um, dm);
if(temp == null)
System.out.println("Sorry - No movie is available with the specified rating and budget requirement");
else
System.out.println(temp.id);
}
public static int findAvgBudgetByDirector (Movie[] mv, String nm)
{
//method logic
int avg,s=0,j=0;
for(int i=0;i<4;i++)
{
if(nm.equalsIgnoreCase(mv[i].dt))
{
s = s+mv[i].bt;
j++;
}
}
if(j>0)
{
avg = s/j;
return avg;
}
else
return 0;
}
public static Movie getMovieByRatingBudget(Movie[] mv, int rating, int budget)
{
//method logic
Movie temp = new Movie();
for(int i=0;i<4;i++)
{
if((rating == mv[i].rt) && (budget == mv[i].bt) && (mv[i].bt % mv[i].rt == 0))
{
temp.id = mv[i].id;
return temp;
}
}
return null;
}
}
class Movie
{
//code to build Movie class
int id,rt,bt;
String dt;
Movie()
{
}
Movie(int id, String dt, int rt, int bt)
{
this.id = id;
this.dt = dt;
this.rt = rt;
this.bt = bt;
}
}
No comments:
Post a Comment