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

How to Introduce Yourself to project team and client when you join a new project as fresher in service based company ?

Question:     How to Introduce Yourself to project team /client  when you join a new project as fresher ? Answer:  Hii Everyone,    Today I will be talking about how we can introduce ourselves to a team  when we join a new project in any servicebased company as a fresher.     After I completed my Engineering ,I got placed into TCS.I got allocated  into a project.I introduced myself to a team.So I will be telling about how   exactly I introduced myself to the team.The impressive introduction is  necessary if you want team members to treat you better in this work from  home period.If you fail to impress team members ,If your introduction is not  impressive ,then probably your team members will ignore you.    Before I tell you about how exactly I introduced myself,I would like  to talk about the points that you should remember before giving your  introduction. .start your introduction with Hii Ev...

Automating Infrastructure on Google Cloud with Terraform: Challenge Lab

As more and more organizations move to the cloud, the need for powerful infrastructure automation tools has never been greater. That's where Terraform comes in, a cutting-edge tool that allows you to automate the deployment, management, and scaling of your infrastructure with ease. With Terraform, you can define your entire infrastructure as code, making it easy to maintain, version, and reproduce. Whether you're deploying infrastructure to AWS, Google Cloud, or another cloud provider, Terraform provides a powerful and flexible platform for automating your workflows. In this blog post, we'll take a look at how to automate infrastructure on google cloud with terraform. Task A. Create the configuration files  Task B. Import infrastructure  Task C.Configure a remote backend  Task D. Modify and update infrastructure  Task E.Destroy resources  Task F. Use a module from the Registry  Task G. Configure a firewall ......................................................

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...