练习三方库的使用,根据UML图代写一个电影管理系统。
Requirement
In this homework you will learn how to use external libraries and the java api
in order to display data in custom formats. You will be building a database of
information about movies and the actors in them. We are simulating a database
of movies in a library, so movies may be added (purchased) and removed (ie:
the dvd/blu-ray disc breaks). You will be required to display the data in a
tabular form, sorting actors by name, and number of movies they appear in. You
will be required to sort movies by title and year. In order to gain
information about movies, you will be using the Open Movie Database Api (
http://omdbapi.com ) and the big data library. For extra
credit you must create a GUI with actor and movie tables that are sorted when
the headers are clicked.
Required Classes
Actor
Write a fully documented class named Actor. This class represents
- private String name:
- Field that holds the name of the Actor.
- private int count
- Field that represents the number of movies this actor is in.
- Default value should be 0.
- public Actor(String name)
- Overloaded constructor for creating a new Actor object with the specified name.
- Getters and setters for the above two member fields.
Movie
- private String title
- Field that holds the title of the movie.
- private int year
- Field that holds the year the movie was released.
- private List Actor
- Field that holds the list of actors who were in the movie, represented as actors.
- public Movie(String title, int year)
- Overloaded constructor for creating a new movie with given details and an empty, non-null actors list.
- public Movie(String url)
- Loads (using BigData) a movie from the passed URL and makes a new Movieobject from it. This is an example of an overloaded constructor.
- Getters and Setters for the above three member variables.
MovieManager
- private List movies (or ArrayList)
- A List Movie or ArrayList Movie, whichever you prefer.
- Field that holds all movies handled by this MovieManager.
- private List Actor actors (or ArrayListActor)
- A List Actor or ArrayList Actor, whichever you prefer.
- Field that holds all actors handled by this MovieManager.
- public MovieManager()
- Constructs a MovieManager object with an empty, non-null actors and movies list.
- public List Movie getMovies()
- Returns the movies list held by this MovieManager.
- public List Actor getActors()
- Returns the actors list held by this MovieManager.
- public List Movie getSortedMovies(Comparator comp)
- Returns a sorted list of movies based on the given comparator
- public List Actor getSortedActors(Comparator comp)
- Returns a sorted list of actors based on the given comparator
Comparator classes
This assignment requires Movie instances to be sorted by two different member
variables: year and title. Actors should be sorted by two member variables as
well (name and movie count). To accomplish this, you should create four
different classes which implement the Comparator interface which allow the
Actor and Movie instances to be arranged in sorted order based on the value of
these member variables.
- YearComparator
- TitleComparator
- NameComparator
- CountComparator
Each of these classes should implement either:
int compare(Movie left, Movie right)
—|—
or
int compare(Actor left, Actor right)
—|—
method. Each method in these classes should compare the two arguments based on
the value of the desired member variable. For example, YearComparator would
compare two Movie objects based on the values of their year member variables.
ASMDB
This is the driver class that shows the user the menu detailed in UI Required
Functions below. It must have a public static main(String[] args), but you can
add extra methods to help you organize each part of the menu.
General Recommendations
You might want to implement a toString() method for classes to make debugging
and printing easier. You do not have to do this, but it will help you.
You can feel free to add any extra methods and variables as you see fit
(public and private).
UI Required Functions
Menu:
- I - Import Movie Title
- D - Delete Movie Title
- M - Sort Movies
- By Title Ascending (TA)
- By Title Descending (TD)
- By Release Date Ascending (YA)
- By Release Date Descending (YD)
- A - Sort Actors
- Alphabetically Ascending (AA)
- Alphabetically Descending (AD)
- By Number of Movies They Are In Ascending (NA)
- By Number of Movies They Are In (ND)
- Q - Quit
Extra Assistance
List vs ArrayList
You may have noticed some datatypes were specified as List Type instead of
ArrayList. This is because List is an interface from the Collections package
which names the common list operations. ArrayList is an implementation. While
you may feel free to use ArrayList Type in place of every List referenced
throughout, by using List you will ensure that your code would work if you
were to change to using a linked list instead.
Such details are more important in design-based Computer Science classes, but
an early introduction is helpful.
Big Data Library
This assignment requires information to be extracted from XML files provided
by the OMDBAPI (Open Movie Database API) service. In order to simplify the
data extraction process, you can use the BigData library to parse Movie
records from the datasets. This library provides several powerful data
extraction tools for XML and JSON formatted data, and is capable of
transforming structured text into Java objects using a special constructor
convention.
In order to utilize the BigData library, you must include bigdata.jar in to
your project. You can include a JAR file in the following manner, depending on
your IDE:
Using a JAR in Eclipse
Right click the project name in the “Package Explorer” tab (on the left, by
default) - Select “Build Path” - Select “Add External Archives…” - Navigate to
where you saved bigdata.jar and select it.
Using a JAR NetBeans
Right click the project name in the “Package Explorer” tab (on the left, by
default) - Click on “Properties” - Select “Libraries” on the left - Click on
“Add JAR/Folder” on the right - Navigate to where you saved bigdata.jar and
select it.
Using a JAR in IntelliJ
[ http://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-
lib-jar-to-an-intellij-idea-project
](http://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-
lib-jar-to-an-intellij-idea-project)
Using a JAR on the command line
[ http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-
commandline-javac-or-apt
](http://stackoverflow.com/questions/2096283/including-jars-in-classpath-on-
commandline-javac-or-apt)