Question
Java Implementation: Distributor class The Distributor class represents a distributor of movies. Every movie has at most one distributor and every distributor can distribute zero
Java Implementation:
Distributor class The Distributor class represents a distributor of movies. Every movie has at most one distributor and every distributor can distribute zero or more movies. (In this simplistic application, a distributor can distribute at most five movies.) The Distributor class has the following instance variables, named exactly as follows: name: a string that represents the distributor's name. address: a string that represents the distributors address. phone: a string that represents the distributors phone. movies: an instance variable of type array of Movie with length of 5. numberOfMovies: an integer that indicates the number of movies that have been added to the movies array. Implement the following for the Distributor class. Use the names exactly as given (where applicable) and in the other cases, use standard naming conventions.
A constructor that takes as input only the distributor's name, address, and phone in that order, and creates the distributor by initializing the fields appropriately, and instantiating the array movies. Each Movie reference in the array will initially be null.
Getters and setters for name, address, and phone.
A getter for movies. Use Arrays.copyOf to trim the array to the exact number of movies and return the trimmed array. The following statement does the trick. return Arrays.copyOf(movies, numberOfMovies);
addMovie: a method that takes a single parameter of type Movie and returns a boolean. Themethod attempts to add themoviesupplied asparameter to themovies array. If the number of movies is greater than or equal to the length of the array, the movie does not get added and the method returns false. Otherwise, the movie is added and the method returns true. Note that movies[0]must be filled before movies[1] and movies[1]must be filled before movies[2], etc. The field numberOfMovies is updated as necessary.
addMovie: this an overload of addMovie method that takes four input parameters that represent a movie's name, directorName, genre, and earnings (in that order) and returns a boolean. The method creates a Movie object using the input parameters and attempts to add that object to the movies array. If the number of movies is greater than or equal to the length of the array, the movie does not get added and the method returns false. Otherwise, the movie is added and the method returns true. Note that movies[0]must be filled before movies[1]and movies[1]must be filled before movies[2], etc. The field numberOfMovies is updated as necessary.
totalNumMovies: a method that returns as output the number of movies of that distributor.
findTotalEarnings: a method that returns as output the total earnings for the distributor which is the sum of all earnings for the distributor's movies. comedyEarnings: a method that returns as output the total earnings of movies of the comedy genre.
addEarnings: a method that takes as input two parameters that represent a movie's name and earnings and returns a boolean as output. The method searches the movies array for a movie with the same name as the input name (case insensitive) and add the input earnings to the movie's earnings if the movie is found and return True. The method returns False if the input movie name is not found.
getNumGenre: a method that takes as input an integer that represents a genre (i.e., 0, 1, or 2) and returns as output the number of distributor's movies of that genre. The method returns -1 if the input is invalid (i.e., less than 0 or greater than 2).
calculateTax: a static method that takes two input parameters that represent (1) the tax rate (e.g., 10%) and (2) a distributor. The method returns as output the amount of tax that need to be paid by the distributor based on the total distributor's earning. For example, if the total earning for a distributor is $1M and the tax rate is 5%, then the method returns 50000.
equals: a method to test the equality of two distributors. Two distributors are considered to be equal if they have the same name and the comparison must be case insensitive. Ensure that your implementation satisfies all of the requirements of the equals method specified in the JDK documentation.
toString(): a method that returns a string representation of the distributor that includes the following:
distributor's name, address, and phone. number of movies for this distributor, details of all the movies, one per line the total earnings for that distributor,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started