Question: I have a code that needs to be adjusted to get the outcome needed. question is the following: Assume that a list of movies produced

I have a code that needs to be adjusted to get the outcome needed.

question is the following: Assume that a list of movies produced in different years are listed in a text file.Assume that the name of the text file is movies.txt.For example, here is some set of movies. Please feel to add, change, edit the test data.

Fargo, 1970

Wanda, 1970A

irport, 1970

Red Sun, 1971

Solaris, 1971

Fargo, 1990

Airport, 1981

You will write a program

To read this text file

To construct a movie object with two fields (name and year_made) for each line read

To construct a collection of movies

To identify whether the given collection has any movies with the same name

To report out any movies with the duplicate names.

For example, here is a sample output of the program if there are no duplicates

File movies.txt is processed.

There are no duplicate movies.

For example, here is a sample output of the program if there are duplicates

File movies.txt is processed.

Here are the movies with the duplicate names.

Fargo, 1970

Fargo, 1990

Airport, 1970

Airport, 1981

the code I have so far is this:

MovieCollection class:

import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner;

public class MovieCollection { ArrayList movieList = new ArrayList(); public void printDuplicates(Scanner sc){ } public String toString() { return movieList.toString(); } public static void main(String[] args) throws IOException { MovieCollection m = new MovieCollection(); File file = new File("C:\\Users\\Quirna\\eclipse-workspace\\ICS 370 - solution 1\\src\\movies.txt"); Scanner sc = new Scanner(file); Scanner scanner = new Scanner(System.in); ArrayList movieList = new ArrayList(); while (sc.hasNextLine()) { String[] movie_data = sc.nextLine().split(","); Movie e = new Movie(movie_data[0], movie_data[1]); m.movieList.add(e); } m.printDuplicates(); sc.close(); }

}

Movie class:

public class Movie { private String name = "name"; private String year_made = "year_made"; Movie (String name, String year_made){ this.name = name; this.year_made = year_made; } public String getName() { return name; } public String getYear() { return year_made; } public String toString() { return "Name: " + name + "," + "Year: " + year_made; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!