Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Arizona State University - CSE205 Assignment #8 Due Date Wednesday, March 20th, at 5:30pm. URL for full assignment information: https://courses.eas.asu.edu/cse205/current/assignments/assignment8.html Minimal Submitted Files You are

Arizona State University - CSE205 Assignment #8

Due Date

Wednesday, March 20th, at 5:30pm.

URL for full assignment information: https://courses.eas.asu.edu/cse205/current/assignments/assignment8.html

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment8.java(More code need to be added) Movie.java(given by the instructor, it needs to be modified for this assignment) Production.java(given by the instructor, it needs to be modified for this assignment) MovieTitleComparator.java MovieYearComparator.java ProductionComparator.java Sorts.java MovieArrangement.java

Class Diagram:

image text in transcribed

Production

The Production class implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" package.) It needs to define the following method:

public void copy(Production other)

It needs to copy every member variable value from "other" parameter to their corresponding variable of the object itself using "this" reference. For instance, if we have two objects of Production, production1 and production2, then, executing the following statement: production1.copy(production2) should resulting to have the object production1 to have the same companyName, locationCity, and locationState value as the ones for production2, but production1 and production2 should not become aliases.

Movie

The Movie class implements the "Serializable" interface so that its object can be stored. (The Serializable interface is defined in the "java.io" package.) It needs to define the following method:

public void copy(Movie other)

It needs to copy every member variable value from "other" parameter to their corresponding variable of the object itself using "this" reference.

MovieTitleComparator

The MovieTitleComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define: public int compare(Movie first, Movie second) instead by making the class implements Comparator.

The movie titles of the first argument and the second argument need to be compared (in alphabetical order -- compareTo method of the String class). If the first argument object has its movie title less than that of the second argument, an int less than zero is returned. If the first argument object has its movie title larger than that of the second argument, an int greater than zero is returned. If their movie titles are same, then 0 should be returned.

MovieYearComparator

The MovieYearComparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define: public int compare(Movie first, Movie second) instead by making the class implements Comparator.

If the first argument object has its year less than that of the second argument, an int less than zero is returned. If the first argument object has its year larger than that of the second argument, an int greater than zero is returned. If their years are same, then 0 should be returned.

ProductionLocationCamparator

The ProductionLocationCamparator class implements the "Comparator" interface (The Comparator interface is in "java.util" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define: public int compare(Movie first, Movie second) instead by making the class implements Comparator.

If the first argument object has its locationState less than that of the second argument, an int less than zero is returned. If the first argument object has its locationState larger than that of the second argument, an int greater than zero is returned. If their locationStates are same, then their cities should be compared. (if the first argument object has its cities smaller (in alphabetical order -- compareTo method of the String class), then it should return a negative integer. If the first argument object has its city larger, then it should return a positive integer. If their locationStates and locationCities are same, then 0 should be returned.

Sorts

The Sorts class is a utility class that will be used to sort a list of Movie objects. Sorting algorithms are described in the algorithm note posted under Notes section of the course web site. These algorithms sort numbers stored in an array. It is your job to modify it to sort an array of objects. The Sorts class object will never be instantiated. It must have the following methods:

public static void sort(Movie[] movieList, int size, Comparator)

Your sort method utilizes the compare method of the parameter Comparator object to sort. You can use one of Selection sort, Insertion Sort, MergeSort, or QuickSort. The parameter size specifies how many first elements should be sorted. Note that not all elements in the array should be sorted, since some of them will be null pointers.

MovieArrangement

The MovieArrangement class has a list of Movie objects that can be organized at the movie arrangement system. The movie arrangement system will be a fully encapsulated object. The MovieArrangement class implements the Serializable interface. It has the following attributes:

Attribute name Attribute type Description
movieList an array of Movie objects A list of Movie objects in the movie arrangement system
currentMovieCount int the number of Movie objects created and stored in the movieList
maxSize int the maximum number of Movie objects that can be stored in the movieList array. It is also the size of the movieList array.

The following public methods should be provided to interact with the movie arrangement system:

Method Description
MovieArrangement(int maximumsize) A Constructor of the MovieArrangement class. Using the parameter value, it should initialize the member variable maxSize. Then it should instantiate an array of Movie objects using the maxSize, and initialize each slot of the array to null for every index. It should also initialize the member variable currentMovieCount to 0.
int movieExists(String movieTitle, int year) Search for a Movie object by movieTitle and its year, and return the index of the object if found. Return -1 if not found. The parameters are the title and the year of a Movie object.
int productionExists(String companyName, String locationCity, String locationState) Search for a Movie object in the movie list that have the same company name, city, and state as the parameter values and return the index of such object if found. Return -1 if not found.
boolean addMovie(String title, int length, int year, String companyName, String locationCity, String locationState) Add a Movie object to the movie list and return true if such object was added successfully. Return false if an object with the same movie title and year already exists or currentMovieCount is already same as maxSize, i.e., the array is full (the new object is not added).
boolean removeMovie(String movieTitle, int year) Remove a Movie object of the parameter movieTitle and the year from the movie list. Return true if the object was removed successfully. Return false if the object with the given movie title does not exist.
void sortByMovieTitles() Sort the list of Movie objects by movie titles. This method calls the sort method defined in the Sorts class, using the movieList, and its maxSize, an object of MovieTitleComparator class.
void sortByMovieYears() Sort the list of Movie objects by movie years. This method calls the sort method defined in the Sorts class, using the movieList, and its maxSize, an object of MovieYearComparator class.
void sortByProductions() Sort the list of Movie objects by their production information including its city and state This method calls the sort method defined in the Sorts class, using the movieList, and its maxSize, an object of ProductionLocationComparator class.
String listMovies() List all Movie objects in the movie list. The returned string is the concatenation of each Movie object information in the list for the number of currentMovieCount (do not use the size of the array here) Hint: you can utilize Movie's toString method to help you complete this method. If there is no object in the list, This method should return the string containing " no movie ".
void closeMovieArrangement() Closes the movie arrangement system by making the movieList empty. This can be done by making every slot of the movieList array to null, and also by setting currentMovieCount to be 0.

No input/output should occur in the movie arrangement system. User interaction should be handled only by the driver class.

You may add other methods to the class in order to make your life easier.

Assignment8

All input and output should be handled in Assignment8 class.

Add Movie

This part is already implemented in Assignment8.java file. Please see the case A in the main of Assignment8.java.

Create MovieArrangement

This part is already implemented in Assignment8.java file. Please see the case C in the main of Assignment8.java.

Search by Movie

This part is already implemented in Assignment8.java file. Please see the case D in the main of Assignment8.java.

Search by Production

This part is already implemented in Assignment8.java file. Please see the case E in the main of Assignment8.java.

Sort by Movie Titles

This part is already implemented in Assignment8.java file. Please see the case N in the main of Assignment8.java.

Sort by Movie Years

This part is already implemented in Assignment8.java file. Please see the case O in the main of Assignment8.java.

Sort by Productions

This part is already implemented in Assignment8.java file. Please see the case P in the main of Assignment8.java.

Remove by Movie

This part is already implemented in Assignment8.java file. Please see the case R in the main of Assignment8.java.

List Movies

Each Movie object information in the movie list should be displayed using the toString method provided in the Movie class. (and use listMovies( ) method in the MovieArrangement class.) This part is already implemented in Assignment8.java file. Please see the case L in the main of Assignment8.java.

Close MovieArrangement

Delete all Movie objects. Then, display the following:

movie arrangement system closed This part is already implemented in Assignment8.java file. Please see the case R in the main of Assignment8.javaT

Write Text to File

Your program should display the following prompt:

Please enter a file name to write:

Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:

Please enter a string to write in the file:

Read in the string that a user types, say "input", then attach " " at the end of the string, and write it to the file. (i.e. input+" " string will be written in the file.)

If the operation is successful, display the following:

FILENAME was written

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch IOException. The file should be closed in a finally statement.

Read Text from File

Your program should display the following prompt:

Please enter a file name to read:

Read in the file name create appropriate objects to get ready to read from the file. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read

Then read only the first line in the file, and display:

The first line of the file is:

CONTENT

where CONTENT should be replaced by the actual first line in the file.

Your program should catch the exceptions if there are. (Use try and catch statement to catch, FileNotFoundException, and the rest of IOException.)

If the file name cannot be found, display

FILENAME was not found

where FILENAME is replaced by the actual file name.

Serialize MovieArrangement to File

Your program should display the following prompt:

Please enter a file name to write:

Read in the filename and write the serialized MovieArrangement object (the variable production1) out to it. Note that any objects to be stored must implement Serializable interface. The Serializable interface is defined in java.io.* package. If the operation is successful, display the following:

FILENAME was written

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch NotSerializableExeption and IOException.

Deserialize MovieArrangement from File

Your program should display the following prompt:

Please enter a file name to read:

Read in the file name and attempt to load the MovieArrangement object from that file. Note that there is only one MovieArrangement object (the variable production1) in the Assignment8 class, and the first object read from the file should be assigned to the MovieArrangement object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read

Your program should catch the exceptions if there are.

(Use try and catch statement to catch ClassNotFoundException, FileNotFoundException, and the rest of IOException.)

See the output files for exception handling.

MovieTitleComparator MovieYearComparator ProductionLocationComparator +compare( Object,Object):int +compare(Object, Object):int +compare(Object, Object):int 1Production Movie MovieArrangement -movieList:Moviel] -currentMoviesCount:int maxSize int Assignments Movie/Arrangement( Int) +movieExists(String, int) int +productionExists(String, String, String):int +addMovie(String.int,int,String,String.String):boolean +removeMovie(String, int):boolean +sortByMovieTitle0:void +sortByMovieYer:void +sortByProductionOvoid +listMoviesO:String +closeMovieArrangement:void +main(String:void printMenuO:void Assignment8 CSE205 Arizona State University Spring 2019 Sorts +sort(Moviel], int, Comparator Movie>):void MovieTitleComparator MovieYearComparator ProductionLocationComparator +compare( Object,Object):int +compare(Object, Object):int +compare(Object, Object):int 1Production Movie MovieArrangement -movieList:Moviel] -currentMoviesCount:int maxSize int Assignments Movie/Arrangement( Int) +movieExists(String, int) int +productionExists(String, String, String):int +addMovie(String.int,int,String,String.String):boolean +removeMovie(String, int):boolean +sortByMovieTitle0:void +sortByMovieYer:void +sortByProductionOvoid +listMoviesO:String +closeMovieArrangement:void +main(String:void printMenuO:void Assignment8 CSE205 Arizona State University Spring 2019 Sorts +sort(Moviel], int, Comparator Movie>):void

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions