Solution5

 package pone;

import java.util.*;

class Movies
{
private int movieId;
private String movieName;
private int movieRating;
private int numberOfActors;
private ArrayList<String> actors;

public Movies(int movieId,String movieName,int movieRating,int numberOfActors,ArrayList<String> actors)
{
this.movieId = movieId;
this.movieName = movieName;
this.movieRating = movieRating;
this.numberOfActors = numberOfActors;
this.actors = actors;
}


public int getMovieId() {
return movieId;
}

public Movies setMovieId(int movieId) {
this.movieId = movieId;
return this;
}

public String getMovieName() {
return movieName;
}

public Movies setMovieName(String movieName) {
this.movieName = movieName;
return this;
}

public int getMovieRating() {
return movieRating;
}

public Movies setMovieRating(int movieRating) {
this.movieRating = movieRating;
return this;
}

public int getNumberOfActors() {
return numberOfActors;
}

public Movies setNumberOfActors(int numberOfActors) {
this.numberOfActors = numberOfActors;
return this;
}

public ArrayList<String> getActors() {
return actors;
}

public Movies setActors(ArrayList<String> actors) {
this.actors = actors;
return this;
}
}

class MovieService
{
//Task 1: Fetch List of Movies Based on the Actor
public void task1(ArrayList<Movies> mov,String input1)
{
int count = 0;
ArrayList<String> ans = new ArrayList<>();
for(Movies mm : mov)
{
for(String ac : mm.getActors())
{
if(ac.equalsIgnoreCase(input1))
{
ans.add(mm.getMovieName());
count++;
}
}
}
if(count == 0)
{
System.out.println("No Movies found");
}
else
{
for(String ss : ans)
{
System.out.println(ss);
}
}

}

//Task 2: Calculate Average Movie Rating based on the Actor
public void task2()
{

}

}

public class Solution5
{
public static void main(String[] args)
{
Scanner xx = new Scanner(System.in);
MovieService yy = new MovieService();
ArrayList<Movies> mov = new ArrayList<>();
int n = xx.nextInt();xx.nextLine();
for(int i = 0; i < n; i++)
{
int movieId = xx.nextInt();xx.nextLine();
String movieName = xx.nextLine();
int movieRating = xx.nextInt();xx.nextLine();
int numberOfActors = xx.nextInt();xx.nextLine();
ArrayList<String> act = new ArrayList<>();
for(int j = 0; j < numberOfActors; j++)
{
String actor = xx.nextLine();
act.add(actor);
}
mov.add(new Movies(movieId,movieName,movieRating,numberOfActors,act));

}
String input1 = xx.nextLine();
String input2 = xx.nextLine();
yy.task1(mov,input1);
//yy.task2(mov,input2);


}
}

Comments

Popular posts from this blog

Restaurant

TimePass

UIUXFILES