Menu

(Solved) : Implement Java Distributor Class Distributor Class Represents Distributor Movies Every Mov Q44138187 . . .

implement in Java:
Distributor class
The Distributor class represents a distributor of movies. Everymovie has at most
one distributor and every distributor can distribute zero or moremovies.
(In this simplistic application, a distributor can distribute atmost five movies.) The
Distributor class has the following instance variables, namedexactly as follows:
• name: a string that represents the distributor’s name.
• address: a string that represents the distributor’saddress.
• phone: a string that represents the distributor’s phone.
• movies: an instance variable of type array of Movie with lengthof 5.
• numberOfMovies: an integer that indicates the number of moviesthat have
been added to the movies array.
Implement the following for the Distributor class. Use the namesexactly as given
(where applicable) and in the other cases, use standard namingconventions.
• A constructor that takes as input only the distributor’s name,address, and
phone in that order, and creates the distributor by initializingthe fields
appropriately, and instantiating the array movies. Each Moviereference 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 theexact
number of movies and return the trimmed array. The followingstatement does
the trick.
return Arrays.copyOf(movies, numberOfMovies);
• addMovie: a method that takes a single parameter of type Movieand returns a
boolean. Themethod attempts to add themoviesupplied asparameter tothemovies
array. If the number of movies is greater than or equal to thelength 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 filledbefore movies[1]
and movies[1]must be filled before movies[2], etc. The fieldnumberOfMovies
is updated as necessary.
• addMovie: this an overload of addMovie method that takes fourinput parameters
that represent a movie’s name, directorName, genre, and earnings(in thatorder) and returns a boolean. The method creates a Movieobject using the input
parameters and attempts to add that object to the movies array. Ifthe number of
movies is greater than or equal to the length of the array, themovie does not get added
and the method returns false. Otherwise, the movie is added and themethod returns
true. Note that movies[0]must be filled before movies[1]andmovies[1]must
be filled before movies[2], etc. The field numberOfMovies isupdated as
necessary.
• totalNumMovies: a method that returns as output the number ofmovies of that
distributor.
• findTotalEarnings: a method that returns as output the totalearnings for the
distributor which is the sum of all earnings for the distributor’smovies.
• comedyEarnings: a method that returns as output the totalearnings of movies of
the comedy genre.
• addEarnings: a method that takes as input two parameters thatrepresent a movie’s
name and earnings and returns a boolean as output. The methodsearches the movies
array for a movie with the same name as the input name (caseinsensitive) and add the
input earnings to the movie’s earnings if the movie is found andreturn True. The
method returns False if the input movie name is not found.
• getNumGenre: a method that takes as input an integer thatrepresents a genre (i.e.,
0, 1, or 2) and returns as output the number of distributor’smovies of that genre. The
method returns -1 if the input is invalid (i.e., less than 0 orgreater than 2).
• calculateTax: a static method that takes two input parametersthat represent (1)
the tax rate (e.g., 10%) and (2) a distributor. The method returnsas output the amount
of tax that need to be paid by the distributor based on the totaldistributor’s earning.
For example, if the total earning for a distributor is $1M and thetax rate is 5%, then the
method returns 50000.
• equals: a method to test the equality of two distributors. Twodistributors are
considered to be equal if they have the same name and thecomparison must be
case insensitive. Ensure that your implementation satisfies all ofthe requirements
of the equals method specified in the JDK documentation.
• toString(): a method that returns a string representation of thedistributor 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,

Expert Answer


Answer to implement in Java: Distributor class The Distributor class represents a distributor of movies. Every movie has at most o…

OR