Here is the code I have done so far. I keep getting Java null point exception for makeMovielist code: import java.util.ArrayList; import java.util.Arrays; public class MovieList { /** * This method...


Here is the code I have done so far. I keep getting Java null point exception for makeMovielist


code:


import java.util.ArrayList;


import java.util.Arrays;


public class MovieList {






/**


* This method will take the name of a movie and delete it


* in the movies if exists and


* delete its corresponding year in years


*


* @param name movie name to delete


* @param movies List of all movies' name


* @param years List of corresponding years


*/


public static void deleteMovieByName(String name, ArrayList movies,


ArrayList years) {


if(name==null || movies == null || years == null)


return;


for(int i=0; i


if(movies.get(i).equals(name)){


movies.remove(i);


years.remove(i);


}


}


}


/**


* This method will delete all movies with specific year


* in the movie list and year list


*


* @param year the given year


* @param movies List of all movies' name


* @param years List of corresponding years


*/


public static void deleteMoviesByYear(int year, ArrayList movies,


ArrayList years) {


if(movies == null || years == null)


return;


for(int i=0; i


if(years.get(i)==year){


movies.remove(i);


years.remove(i);


}


}


}


/**


* This method will return a string that contains each


* movie name and its year.


* Each line will format as follow:


* ()\n


*


* @param movies List of all movies' name


* @param years List of corresponding years


* @return string contains all movie names and years


*/


public static String makeMovieList(ArrayList movies,


ArrayList years) {


String result = "";


for(int i=0; i


result += movies.get(i)+" ("+years.get(i)+")\n";


}




return result;


}


/**


* test for deleteMovieByName()


* @param movies


* @param years


*/


public static void testDeleteByName(ArrayList movies,


ArrayList years) {


boolean error = false;


deleteMovieByName("Fight Club", movies, years);


ArrayList expectedMovie1 = new ArrayList<>(


Arrays.asList("The Shawshank Redemption","The Godfather",


"The Godfather: Part II", "The Dark Knight",


"12 Angry Men", "Schindler's List",


"The Lord of the Rings: The Return of the King",


"Pulp Fiction", "The Good, the Bad and the Ugly"


));


ArrayList expectedYears1 = new ArrayList<>(


Arrays.asList(1994, 1972, 1974, 2008, 1957,


1993, 2003, 1994, 1966));


if(!movies.equals(expectedMovie1) || !years.equals(expectedYears1)){


error = true;


System.out.println("Expected movie list: " + expectedMovie1);


System.out.println("Actual movie list: " + movies);


System.out.println("Expected movie list: " + expectedYears1);


System.out.println("Actual movie list: " + years);


}


//add more test cases


if(error){


System.out.println("testDeleteByName fail");


}else{


System.out.println("testDeleteByName pass");


}


}


/**


* test for deleteMoviesByYear()


* @param movies


* @param years


*/


public static void testDeleteByYear(ArrayList movies,


ArrayList years) {


}


/**


* test for makeMovieList()


* @param movies


* @param years


*/


public static void testMakeMovieList(ArrayList movies,


ArrayList years) {


}


public static void main(String[] args) {


ArrayList movies = new ArrayList<>(


Arrays.asList("The Shawshank Redemption","The Godfather",


"The Godfather: Part II", "The Dark Knight",


"12 Angry Men", "Schindler's List",


"The Lord of the Rings: The Return of the King",


"Pulp Fiction", "The Good, the Bad and the Ugly",


"Fight Club"


)


);


ArrayList years = new ArrayList<>(


Arrays.asList(1994, 1972, 1974, 2008, 1957,


1993, 2003, 1994, 1966, 1999));


testDeleteByName(movies, years);


//testDeleteByYear(movies, years);


//testMakeMovieList(movies, years);


}


}



9.9 **zyLab: MovieList<br>Write this program using Eclipse or IntelliJ. Comment and style the code according to CS 200 Style Guide. Submit the source code files<br>(java) below. Make sure your source files are encoded in UTF-8.<br>The goal of this problem is to get familiar with ArrayLists. As opposed to an array, an ArrayList is dynamic; when you delete an element in<br>the ArrayList, the size of the ArrayList will change.<br>In this lab, you will create methods that simultaneously alter two parallel ArrayLists. One String ArrayList saves the name of the movie, the<br>other Integer ArrayList saves the corresponding year of the movie. You will implement three methods: deleteMovieByName(),<br>deleteMoviesByYear(), and makeMovieList(). A downloadable file named MovieList.java is available to help you get started.<br>1. Implement the deleteMovieByName(String name, ArrayList<String> movies, ArrayList<Integer> years)<br>method:<br>o If the given string name of the movie exists, delete the movie in the ArrayList<String> movies and the corresponding<br>year in the ArrayList<Integer> years<br>O ArrayList and String are reference types, so the method should check whether they are null first. If any of the ArrayList is<br>null, the method should return immediately.<br>/**<br>This method will take the name of a movie and delete it<br>* in the movies if exists and<br>delete its corresponding year in years<br>* @param name movie name to delete<br>@param movies List of all movies' name<br>* @param years List of corresponding years<br>*/<br>public static void deleteMovieByName (String name, ArrayList<String> movies,<br>

Extracted text: 9.9 **zyLab: MovieList Write this program using Eclipse or IntelliJ. Comment and style the code according to CS 200 Style Guide. Submit the source code files (java) below. Make sure your source files are encoded in UTF-8. The goal of this problem is to get familiar with ArrayLists. As opposed to an array, an ArrayList is dynamic; when you delete an element in the ArrayList, the size of the ArrayList will change. In this lab, you will create methods that simultaneously alter two parallel ArrayLists. One String ArrayList saves the name of the movie, the other Integer ArrayList saves the corresponding year of the movie. You will implement three methods: deleteMovieByName(), deleteMoviesByYear(), and makeMovieList(). A downloadable file named MovieList.java is available to help you get started. 1. Implement the deleteMovieByName(String name, ArrayList movies, ArrayList years) method: o If the given string name of the movie exists, delete the movie in the ArrayList movies and the corresponding year in the ArrayList years O ArrayList and String are reference types, so the method should check whether they are null first. If any of the ArrayList is null, the method should return immediately. /** This method will take the name of a movie and delete it * in the movies if exists and delete its corresponding year in years * @param name movie name to delete @param movies List of all movies' name * @param years List of corresponding years */ public static void deleteMovieByName (String name, ArrayList movies,
1: File Header Test a<br>1/1<br>2: Unit Test: deleteMovieByName() ^<br>3/3<br>3: Unit Test: deleteMovieByYear() ^<br>3/3<br>4: Unit Test: makeMovieList() ^<br>0/3<br>Test feedback<br>java.lang.NullPointerException<br>

Extracted text: 1: File Header Test a 1/1 2: Unit Test: deleteMovieByName() ^ 3/3 3: Unit Test: deleteMovieByYear() ^ 3/3 4: Unit Test: makeMovieList() ^ 0/3 Test feedback java.lang.NullPointerException

Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here