Question
In the second part of your project, you are to write a Movie Application that stores a library of movies and implements several functionalities, such
In the second part of your project, you are to write a Movie Application that stores a library of movies and implements several functionalities, such as printing all movies in the library.
We provide the following files here: http://www.research.cs.rutgers.edu/~anapaula/cs111/cs111MovieApp.zip:
IO.java: the IO class
Movie.java: the Movie class from the first part of the project
MovieApp.java: the application file you are to update and submit
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. Fill in the code in the methods MovieApp, addMovie, removeMovie, getMovies, getNumberOfItems, updateRating, print, getMovieByDirector, getMovieByYear, and getMoviesWithRatingsGreaterThan.
Submit the file MovieApp.java
Observe the following rules:
DO NOT add any import statements to MovieApp.java
DO NOT change the headers of ANY of the given methods
DO NOT change/remove any of the given class fields
DO NOT add any new class fields
DO NOT use System.exit()
DO NOT use the IO module in MovieApp.java
YOU MAY add new helper methods, but you must declare them private
If you wish to change MovieDriver, feel free. You are not submitting it.
This is the code I have but when I tried to compile I got this error message:
MovieApp.java:55: error: cannot find symbol
System.out.println(items[i]);
^
symbol: variable i
location: class MovieApp
1 error
I don't see what I did wrong. Please help me fix this!!
import java.util.Arrays;
public class MovieApp {
private Movie[] items;
private int numberOfItems;
MovieApp() {
items = new Movie[20];
numberOfItems = 0;
}
MovieApp(int capacity) {
items = new Movie[capacity];
numberOfItems = 0;
}
public void addMovie(Movie m) {
if (numberOfItems < items.length) {
items[numberOfItems++] = m;
}
else {
items = Arrays.copyOf(items, items.length * 2);
items[numberOfItems++] = m;
}
}
public boolean removeMovie(Movie m) {
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;
}
public Movie[] getMovies() {
return items;
}
public int getNumberOfItems() {
return numberOfItems;
}
public boolean updateRating(Movie m, int ratings) {
for (int i = 0; i < numberOfItems; i++) {
if (items[i].equals(m)) {
items[i].setRatings(ratings);
return true;
}
}
return false;
}
public void print() {
System.out.println(items[i]);
}
public Movie[] getMoviesByDirector(String director) {
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;
}
public Movie[] getMoviesByYear(int year) {
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;
}
public Movie[] getMoviesWithRatingsGreaterThan(int ratings) {
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;
}
}
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