Solution5a
/*
package pone;
import java.util.*;
public class Solution5a
{
public static void main(String[] args)
{
Scanner xx = new Scanner(System.in);
MoviesService yy = new MoviesService();
int a = xx.nextInt();
xx.nextLine();
ArrayList<Movies> mov = new ArrayList<>();
for (int i = 0; i < a; i++) {
int movieId = xx.nextInt();
xx.nextLine();
String movieName = xx.nextLine();
int movieRating = xx.nextInt();
xx.nextLine();
int numberOfActor = xx.nextInt();
xx.nextLine();
List<String> actors = new ArrayList<>();
for (int j = 0; j < numberOfActor; j++) {
String aname = xx.nextLine();
actors.add(aname);
}
mov.add(new Movies(movieId, movieName, movieRating, numberOfActor, actors));
}
String ActorName1 = xx.nextLine();
String ActorName2 = xx.nextLine();
ArrayList<Movies> mv = yy.FetchListofMoviesBasedontheActor(mov, ActorName1);
if (mv.isEmpty()) {
System.out.println("No Movies Found");
return;
}
for (Movies m : mv) {
System.out.println(m.getMovieId());
System.out.println(m.getMovieName());
System.out.println(m.getMovieRating());
System.out.println(m.getNumberOfActor());
}
double avg = yy.CalculateAverageMovieRatingbasedontheActor(mov, ActorName2);
if (avg == 0.0) {
System.out.println("No Movies Found");
} else {
System.out.println(avg);
}
}
}
class Moviess
{
private int movieId;
private String movieName;
private int movieRating;
private int numberOfActor;
private List<String> actors;
public Moviess(int movieId, String movieName, int movieRating, int numberOfActor, List<String> actors) {
this.movieId = movieId;
this.movieName = movieName;
this.movieRating = movieRating;
this.numberOfActor = numberOfActor;
this.actors = actors;
}
public int getMovieId() {
return movieId;
}
public void setMovieId(int movieId) {
this.movieId = movieId;
}
public String getMovieName() {
return movieName;
}
public void setMovieName(String movieName) {
this.movieName = movieName;
}
public int getMovieRating() {
return movieRating;
}
public void setMovieRating(int movieRating) {
this.movieRating = movieRating;
}
public int getNumberOfActor() {
return numberOfActor;
}
public void setNumberOfActor(int numberOfActor) {
this.numberOfActor = numberOfActor;
}
public List<String> getActors() {
return actors;
}
public void setActors(List<String> actors) {
this.actors = actors;
}
}
class MoviesService
{
public ArrayList<Movies> FetchListofMoviesBasedontheActor(ArrayList<Movies> mov, String ActorName1)
{
ArrayList<Movies> str = new ArrayList<>();
for (Movies mo : mov)
{
for (String s : mo.getActors())
{
if (s.equalsIgnoreCase(ActorName1))
{
str.add(mo);
break;
}
}
}
return str;
}
public double CalculateAverageMovieRatingbasedontheActor(List<Movies> mov, String ActorName2) {
double sum = 0;
double average = 0;
double cnt = 0;
for (Movies m : mov) {
for (String s : m.getActors()) {
if (s.equalsIgnoreCase(ActorName2)) {
cnt++;
sum += m.getMovieRating();
break;
}
}
}
if (cnt == 0) {
return 0.0;
}
return sum / cnt;
// To be implemented
}
}
*/
Comments
Post a Comment