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

Can someone please fill in the code for the methods in java language The instruc

ID: 3710758 • Letter: C

Question

Can someone please fill in the code for the methods in java language

The instructions for each method are directly above it

/*

*

* 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 **/

}

/*

* One argument constructor allocates array with user defined capacity

*

* @param capacity defines the capacity of the movie library

*/

MovieApp (int capacity) {

/** COMPLETE THIS METHOD **/

}

/*

* 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 **/

}

/*

* 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

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 null;

}

/*

* 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 0;

}

  

/*

* 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

return false;

}

  

/*

* Prints all movies

*/

public void print () {

/** COMPLETE THIS METHOD **/

}

/*

* 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

return null;

}

  

/*

* 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

return null;

}

/*

* 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

return null;

}

}

Explanation / Answer


In order to complete the code for this class, the Movie class is needed. Based on standard assumptions about the structure of Movie class, I have completed the methods.
I need to know the method names in Movie class to complete this code. In case some methods show errors, please provide me the code of Movie class and I'll help to update this one accordingly.
If its possible to edit the question and paste the Movie class code, please paste it in the question. Otherwise upload the Movie class code in google drive or pasteit and provide me the link.


/*

*

* 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() {

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) {

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) {

if(numberOfItems == items.length)
{
//allocate double capacity
Movie[] temp = new Movie[items.length * 2];
for(int i = 0; i < numberOfItems; i++)
temp[i] = items[i];
items = temp;
}

items[numberOfItems] = m;
numberOfItems++;

}

/*
*
* 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) {

int index = -1;

for(int i = 0; i < numberOfItems; i++)
{
if(items[i].equals(m))
{
index = i;
break;
}
}
if(index == -1) //not found
return false;

//move all others one position to left
for(int i = index + 1; i < numberOfItems; i++)
items[i-1] = items[i];
numberOfItems--;
return true;
}

/*
*
* Returns the library of movies
*
*
*
* @return The array of movies
*
*/

public Movie[] getMovies() {
return items;
}

/*
*
* Returns the current number of movies in the library
*
*
*
* @return The number of items in the array
*
*/

public int getNumberOfItems() {

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) {


for(int i = 0; i < numberOfItems ; i++)
{
if(items[i].equals(m))
{
items[i].setRating(ratings);
return true;
}
}
return false;

}

/*
*
* Prints all movies
*
*/

public void print() {

for(int i = 0; i < numberOfItems; i++)
System.out.println(items[i].toString());
System.out.println();
}

/*
*
* 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) {

int count = 0;
//count how many have specified year

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

if(items[i].getDirector().equalsIgnoreCase(director))
count++;
}

Movie[] result = new Movie[count];
for(int i = 0, j = 0; i < numberOfItems; i++)
{
if(items[i].getDirector().equalsIgnoreCase(director))
result[j++] = items[i];
}
return result;

}

/*
*
* 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) {

int count = 0;
//count how many have specified year

for(int i = 0; i < numberOfItems; i++)
{
if(items[i].getYear() == year)
count++;
}

Movie[] result = new Movie[count];
for(int i = 0, j = 0; i < numberOfItems; i++)
{
if(items[i].getYear() == year)
result[j++] = items[i];
}
return result;
}

/*
*
* 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) {
int count = 0;
//count how many have ratings greater than speicified value

for(int i = 0; i < numberOfItems; i++)
{
if(items[i].getRating() > ratings)
count++;
}

Movie[] result = new Movie[count];
for(int i = 0, j = 0; i < numberOfItems; i++)
{
if(items[i].getRating() > ratings)
result[j++] = items[i];
}
return result;
}

}