Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

=+Where do you want to live and work?

Answered: 1 week ago

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago

Question

=+Are you interested in working on global teams?

Answered: 1 week ago