Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help me write a java code. Movie.java: MovieApp.java: MovieDriver.java: the seco

ID: 3705929 • Letter: H

Question

Help me write a java code.

Movie.java:

MovieApp.java:

MovieDriver.java:

the second part of your project, you are to write a Movie Appl as printing all movies in the library We provide the following files here In ication that stores a library of movies and implements several functionalities, such 1 1O java: the IO class 2 Moviejava the Movie class from the first part of the project 3 MovieApp java: the application file you are to update and submit 4 MovieDriver,java a driver to test your MovieApp MovieApp,java contains all the methods you need to implement. Refer to the methods description on file for your implementation. Fil in the code in the methods MovieApo addluMovie temovelovie getlovies getNumberofitems vadateRating aziat, getovieByDirector getMovießvyear and print Submit the file MovieApp.java rve the following rules DO NOT add any import statements to MovieAppjava DO NOT change the headers of ANY of the given methods DO NOT change/remove any of the given class fielads DO NOT add any new class felds DO NOT use System.exite You MAY add new helper methods, but you must deciare them private you wish to change MovieDriver. feel free You are not submitting t

Explanation / Answer

Please find the below code for MovieApp.java.

I have implemented all the methods and tested using the driver class. Please free to comment back if you have any clarifications. The code for all other classes remains same.

package movie;

import java.util.Arrays;

/*

*

* This class implements a library of movies

*

* @author runb-cs111

*

*/

public class MovieApp {

private Movie[] items; // keep movies in an unsorted array

private int numberOfItems; // number of movies in the array

/*

* Default constructor allocates array with capacity for 20 movies

*/

MovieApp() {

/** COMPLETE THIS METHOD **/

items = new Movie[20];

numberOfItems = 0;

}

/*

* One argument constructor allocates array with user defined capacity

*

* @param capacity defines the capacity of the movie library

*/

MovieApp(int capacity) {

/** COMPLETE THIS METHOD **/

items = new Movie[capacity];

numberOfItems = 0;

}

/*

* Add a movie into the library (unsorted array)

*

* Inserts @m into the first empty spot in the array. If the array is full

* (there is no space to add another movie) - create a new array with double

* the size of the current array - copy all current movies into new array -

* add new movie

*

* @param m The movie to be added to the libary

*/

public void addMovie(Movie m) {

/** COMPLETE THIS METHOD **/

if (numberOfItems < items.length) {

items[numberOfItems++] = m;

} else {

items = Arrays.copyOf(items, items.length * 2);

items[numberOfItems++] = m;

}

}

/*

* Removes a movie from the library. Returns true if movie is removed, false

* otherwise. The array should NOT become sparse after a remove, that is,

* all movies should be in consecutive array indices.

*

* @param m The movie to be removed

*

* @return Returns true is movie is successfuly removed, false otherwise

*/

public boolean removeMovie(Movie m) {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Change as needed for your implementation

for (int i = 0; i < numberOfItems; i++) {

if (items[i].equals(m)) {

if (i == numberOfItems - 1)

numberOfItems--;

else {

for (int j = i; j < numberOfItems - 1; j++) {

items[j] = items[j + 1];

}

numberOfItems--;

}

return true;

}

}

return false;

}

/*

* Returns the library of movies

*

* @return The array of movies

*/

public Movie[] getMovies() {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Change as needed for your implementation

return items;

}

/*

* Returns the current number of movies in the library

*

* @return The number of items in the array

*/

public int getNumberOfItems() {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Changed as needed for your implementation

return numberOfItems;

}

/*

* Update the rating of movie @m to @ratings

*

* @param @m The movie to have its ratings updated

*

* @param @ratings The new ratings of @m

*

* @return tue if update is successfull, false otherwise

*/

public boolean updateRating(Movie m, int ratings) {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Changed as needed for your implementation

for (int i = 0; i < numberOfItems; i++) {

if (items[i].equals(m)) {

items[i].setRatings(ratings);

return true;

}

}

return false;

}

/*

* Prints all movies

*/

public void print() {

/** COMPLETE THIS METHOD **/

for (int i = 0; i < numberOfItems; i++)

System.out.println(items[i]);

}

/*

* Return all the movies by @director. The array size should be the number

* of movies by @director.

*

* @param director The director's name

*

* @return An array of all the movies by @director

*/

public Movie[] getMoviesByDirector(String director) {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Changed as needed for your implementation

Movie[] list = new Movie[0];

int index = 0;

for (int i = 0; i < numberOfItems; i++) {

if (items[i].getDirector().equalsIgnoreCase(director)) {

list = Arrays.copyOf(list, index + 1);

list[index++] = items[i];

}

}

return list;

}

/*

* Returns all the movies made in @year. The array size should be the number

* of movies made in @year.

*

* @param year The year the movies were made

*

* @return An array of all the movies made in @year

*/

public Movie[] getMoviesByYear(int year) {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Changed as needed for your implementation

Movie[] list = new Movie[0];

int index = 0;

for (int i = 0; i < numberOfItems; i++) {

if (items[i].getYear() == year) {

list = Arrays.copyOf(list, index + 1);

list[index++] = items[i];

}

}

return list;

}

/*

* Returns all the movies with ratings greater then @ratings. The array size

* should match the number of movies with ratings greater than @ratings

*

* @param ratings

*

* @return An array of all movies with ratings greater than @ratings

*/

public Movie[] getMoviesWithRatingsGreaterThan(int ratings) {

/** COMPLETE THIS METHOD **/

// THE FOLLOWING LINE IS A PLACEHOLDER TO MAKE THIS METHOD COMPILE

// Changed as needed for your implementation

Movie[] list = new Movie[0];

int index = 0;

for (int i = 0; i < numberOfItems; i++) {

if (items[i].getRatings() > ratings) {

list = Arrays.copyOf(list, index + 1);

list[index++] = items[i];

}

}

return list;

}

}