Skip to main content

Movie_Find_Avg_Budget_By_Director

 Problem Statement

Create a class Movie with the below attributes: movieId - int director - String rating - int budget - int

Write getters, setters and parameterized constructor in the above mentioned attribute sequence as required.

Create class Solution with the main method.

Implement two static methods - findAvgBudgetByDirector and getMovieByRatingBudget in Solution class.

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

getMovieByRatingBudget method: This method will take two int parameters rating and budget, along with the array of movie objects. 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.

Also check if rating is a factor of budget (eg: 3 is a factor of 12 because 3 divides 12 without leaving a remainder). If any of the conditions are not met, then the method should return null.

Note : No two movie object would have the same value for rating and budget attributes. All the searches should be case insensitive. The budget mentioned are in crores and in INR.

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

For findAvgBudgetByDirector method - The main method should print the average budget as it is if the returned value is greater than 0, or it should print "Sorry - The given director has not yet directed any movie".

For getMovieByRatingBudget method - The main method should print the movieId of the returned movie object. If the returned value is null then it should print "Sorry - No movie is available with the specified rating and budget requirement".

Before calling these static methods in main, use Scanner object to read the values of four Movie objects referring attributes in the above mentioned attribute sequence. Next, read the value for director, rating and budget.
Input

1101
GVM
4
100
1201
Shankar
5
500
1301
Shankar
3
50
1401
GVM
5
300
GVM
5
300

Output

200
1401



code:

 

import java.util.Scanner;
public class Solution {
   public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        Movie[] movies = new Movie[4];
        for(int i=0;i<4;i++)
        {
            int movieId = sc.nextInt();sc.nextLine();
            String director = sc.nextLine();
            int rating = sc.nextInt();
            int budget = sc.nextInt();
            movies[i] = new Movie(movieId,director,rating,budget);
        }
        sc.nextLine();
        String searchDirector = sc.nextLine();
        int searchRating = sc.nextInt();
        int searchBudget = sc.nextInt();
        int avgBudget = findAvgBudgetByDirector(movies, searchDirector);
        if (avgBudget>0)
        System.out.println(avgBudget);
        else
        System.out.println("Sorry - The given director has not yet directed any movie");
        Movie resultMovie = getMovieByRatingBudget(movies, searchRating, searchBudget);
        if(resultMovie == null)
        System.out.println("Sorry - No movie is available with the specified rating and budget requirement");
        else
        System.out.println(resultMovie.getMovieId());

    }

    public static int findAvgBudgetByDirector (Movie[] movies, String searchDirector)
      {
          int avg,s=0,j=0;
          for(int i=0;i<4;i++)
          {              
              if(searchDirector.equalsIgnoreCase(movies[i].getDirector()))
              {
                  s = s+movies[i].getBudget();
                  j++;
              }
          }
              if(j>0)
              {
                  avg = s/j;
                  return avg;
              }          
              else
              return 0;
      }

    public static Movie getMovieByRatingBudget(Movie[] movies, int rating, int budget)
      {
          for(int i=0;i<4;i++)
          {
              if((rating == movies[i].getRating()) && (budget == movies[i].getBudget()) && (movies[i].getBudget() % movies[i].getRating() == 0))
              {
                  return movies[i];
              }
          }
          return null;   
          
      }
}

class Movie
{
    private int movieId,rating,budget;
    private String director;

    public int getMovieId() {
        return movieId;
    }

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

    public int getRating() {
        return rating;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public int getBudget() {
        return budget;
    }

    public void setBudget(int budget) {
        this.budget = budget;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    Movie(int movieId, String director, int rating, int budget)
    {
        this.movieId = movieId;
        this.director = director;
        this.rating = rating;
        this.budget = budget;
    }
}

Comments

Popular posts from this blog

TCS IRA 13 DECEMBER JAVA CODING QUESTION SOLUTION.

Create a class newspaper with below attributes. regNo-int name-String publicationYear-int price-int Write parametrised constructor as required. Create class Solution with main method. Implement 2 static methods findTotalPriceByPublicationYear and  searchNewspaperByName in solution class. findTotalPriceByPublicationYear method:    This method will take array of the Newspaper objects and int parameter type.This method will return the total price of newspapers from array of  Newspaper objects,If the publication year attribute matches with the int  parameter passed .If no Newspaper with the given publication year is present  in the array ,then the method should return 0. The main method should print total price if the returned value is greater  than 0.Else it should print "No Newspaper found with the mentioned attribute". searchNewspaperByName method :    This method will take the array of the Newspaper objects and the String  parameter type...

December 23 java coding question PRA solution

23 dec pra java coding question solution. Question: Create the class Student with below attributes. id-int name-String marks-int age-int write getters and setters and parametrized constructor in Student class. Create class Solution with main method. implement 2 static methods-findStudentWithMaximumAge and searchStudentById in Solution class. findStudentWithMaximumAge method:     This method will take the Array of the Students objects as input and  returns the Student object having maximum Age.   For this method,the main method should print the student object details with maximum age as it is.    searchStudentById method:     This method will take 2 input parameters.Array of the Students objects and an int value  id.and returns the Student object having the mentioned id  if found, else return null if not found.   For this method ,main method should print the details of Student objects  as it is,if the returned value is not null....

HTML5 Semantics | Fresco Play | Hands On 6 | Video.

   Question: In this blog Post I am going to explain you how we can solve the below handson. Embed a video in your HTML5 page with a width of '320' and height of '200' with controls displayed. Now, try to do the following: Creating 3 videos Auto-reply the first video preload the second video Display image while the third video loads. Question is provided in the snip below: ......................................................................................................................................... Answer: Code  inside the index.html is provided below : <!DOCTYPE html> <html> <head>   <link rel="icon" href="favicon.png" type="image/png">   <title>Destiny</title>   <link href="mystyle.css" rel="stylesheet" type="text/css"> </head> <body> <video controls autoplay> <source src="video.mp4"> </video>   <video controls prel...