Question
The Movie class represents a movie and has the following attributes: name (of type String), directorName (oftype String), earnings (of type double), and genre (of
The Movie class represents a movie and has the following attributes: name (of type String), directorName (oftype String), earnings (of type double), and genre (of type int). The possible genres are Comedy (0), Action (1) or Fiction (2).
Implement the following for the Movie class. Use the names exactly as given (where applicable) and in the other cases,use standard naming conventions.
- A constructor to initialize all instance variables, except earnings. A value for each instance variable will bepassed as a parameter to the constructor with the exception of earnings, which will be set to zero. Theparameters will be passed in the order name, directorName, then genre.
- Getters for all instance variables.
- A setter method for each instance variable, except earnings.
- addToEarnings: a method than takes as input an amount (of type double) and adds that amount ofmoney to the movies earnings.
- boolean equals(Object obj): a method to test the equality of two movies. Two movies areconsidered to be equal if they have the same name, the same directorName, and the same genreand the comparison for string attributes must be case insensitive.
- String toString(): a method that returns a nicely formatted string description of the movie. All instance variables should be displayed, separated by tabs (use "\t") and the entire Movie should be displayed on one line.
Distributor class
The Distributor class represents a distributor of movies. Every distributor can distribute zero or moremovies and, in this simplistic application, a distributor can distribute at most five movies. The Distributorclass has the instance variables named exactly as follows:
- name: a string that represents the distributor's name,
- phone: a string that represents the distributors phone,
- movies: an instance variable of type array of Movie with length of 5.
- numMovies: an integer that indicates the number of movies that have been added to the movies array. Note that this number can be between 0 and 5.
Implement the following methods 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 the distributor's name and phone (in that order), and creates the distributor byinitializing the fields appropriately, and instantiating the array movies. Each Movie reference in thearray will initially be null by default.
- Getters and setters for name and phone.
- A getter for movies. Use Arrays.copyOf to trim the movies array to the exact number of movies andreturn 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. The method attemptsto add the input movie to the movies array. If the movies array is full, the movie does not get added and themethod returns false. Otherwise, the movie is added and the method returns true. Note that movies[0] mustbe filled before movies[1] and movies[1] must be filled before movies[2], etc. The field numMovies isupdated as necessary.
- addMovie: this is 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 movies array is full, the movie does not get added and the method returns false. Otherwise, the movie is added and the methodreturns true. Note that movies[0] must be filled before movies[1] and movies[1] must be filled beforemovies[2], etc. The field numMovies is updated as necessary.
- getNumMovies: a method that returns as output the number of current number of movies of that distributor.
- totalEarnings: 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 ( of type String and double) that represent a movie's name and earnings respectively and returns a boolean as output. The method searches the movies array for a movie with the same name as the first input parameter (case insensitive) and add the input earnings to that movie's earnings if 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) a double that represent the tax rate (e.g., 0.05 for 5% tax) and (2) an object of type Distributor. The method returns as output the amount of tax that need to be paid by the input distributor based on the distributor's total 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.
- toString: a method that returns a string representation of the distributor that includes the following:
- distributor's name and phone,
- number of movies for this distributor,
- details of all movies, one per line (hint: use toString method of Movie)
- the total earnings for that distributor.
MovieDriver class
Your driver class should perform the following actions:
- Create at least 7 Movie objects with your choice of movie names, director names, and genres.
- Create 2 Distributor objects with your choice of name, address, and phone number.
- Add 5 different movies to the first distributor. Attempt to add the sixth movie to the same distributor and demonstrate that this attempt does not crash the program, but the operation does not succeed.
- Add 2 movies to the second distributor object.
- Print the two distributors.
- Exercise every method of both the Movie and Distributor classes. Demonstrate that they work.
- Do not use a Scanner to read any inputs from the user. Instead, use hard coded values for the different methods' inputs.
Other Requirements
- Draw a UML diagram for your application and make sure to show the relationships between the classes in your solution. You may hand draw or use any tool of your choice but the diagram must be submitted in a format that I can read (one of .doc, .docx, .pdf, .jpg, .txt). If I cannot read it, I cannot grade it.
- Note that automated tools often do not follow the conventions that I require.
- Factor the classes as described above Movie, Distributor, and MovieDriver are all in separate classes
- Comment the Movie and Distributor classes with Javadocs style comments (see Appendix H).
- Use good coding style throughout (see Lecture 1's slides and the CodingStandards.pdf in the Syllabus folder of D2L)including:
- correct private/public access modifiers
- consistent indenting
- meaningful variable names
- normal capitalization conventions
- other aspects of easy-to-read code
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