The aim of the coursework is to produce a simple movie database system. The system has two different user interfaces. We have already written the interface code for you (that is to say we have written the code that displays the available options to the user and allows the user to pick one of those options). Your job is to write the “back end” code that ensures that the correct operations are performed when the user picks an option.

The first interface is a simple menu based “console application” which you should be able to completely understand, so long as you have mastered the topics taught in the course. The second interface is graphical. You will not understand the graphics code (and in fact most of it is hidden in a library so that you cannot even see it).

When the application is finished you will be able to add movies and actors to the database, specify which actors appeared in which movies, save the database to a text file, and load it from a text file. All you have to do for part 1 is to ensure that movies can be added and displayed. You will add more functionalities in parts 2 and 3.

Initial Code

find the file Cwk2Skel.zip. If you unzip this file you should find that you have a NetBeans project containing the following java files.

  • Main.java Code for a menu based interface. You should be able to understand all of the code in this file. You should not modify the file.
  • GUIMain.java Code for a graphical user interface. You do not need to understand the code in this file, and you should not modify it.
  • MovieBase.java This is the “back end” for both the menu-based and graphical interface. At the moment the code is just a skeleton. Your job, over the course of the semester, is to ensure that the methods in this class behave in the way that their documentation says they behave. If you do this correctly then both the menu-based and graphical interfaces will work correctly. You will need to store movies and implement the methods that handle movies to complete part one of the coursework
  • Movie.java A class that represents movies. The code in this class is, at present, just a skeleton. You will need to implement it (attributes and methods) in order to complete part one of the coursework.

The files Main.java and GUIMain.java both have main methods, and both files can be run. If you right click on either file you will get a “run file” option. Running the Main.java file should result in you seeing the following options being displayed in the NetBeans output tab.

Figure 1: The Menu-Based Interface See image.

You should be able to type any of these options into the output window, but nothing will happen, because the back-end code has not been implemented. If you run GUIMain.java you should see the interface shown in Figure 2. If you type some text into the field next to the “Add Movie” button, you should find that button is enabled and that you can click on it. However nothing happens when you do this because the back-end code is not implemented. See image.

What you have to do for Part 1

For part 1 you should:

  • Complete the implementation of the Movie class. To do this you need to add attributes and implement the constructor and the getName method.
  • Add attributes to store Movies and implement the addMovie, getNbrMovies, and getMovie methods of the MovieBase class. You do not need to do anything else.

Here is a brief description of what these constructors and methods should actually do.

Movie class methods and constructor:

  • public Movie(String name) This should construct a Movie object with the appropriate name.
  • public String getName() This method should return the name of the movie.

In other words if you construct a movie by exectuting the statement Movie m = Movie(“The Third Man”) then a call to m.getName() should return the string “The Third Man”.

MovieBase methods:

  • public void addMovie(String movie) This method adds the named movie to the movieBase.
  • public int getNbrMovies() returns the number of movies that have been added.
  • public String getMovie(int i)returns the name of the i’th movie that has been added.

In other words, if you called addMovie(“The Third Man”) followed by addMovie(“Citizen Kame”) on a MovieBase object then you would find that if you called getNbrMovies()on that object then the return value would be 2, if you called getMovie(0) the String “The Third Man” would be returned, and if you called getMovie(1) the String “Citizen Kame” would be returned. Notice that the indexes of the movies start from 0.

You must implement the addMovie method in such a way that it new Movie creates a new Movie object, and you must implement getMovie in such a way that the string returned is obtained by calling getName on a Movie object. A solution that simply creates Strings is not acceptable.

You should find that if you implement all of these methods correctly you should find that the “Add Movie” button on the graphical interface works correctly. In other words, if you type a movie name into the box next to the button, and then click on the button, then the movie is added to a list displayed in the top left of the interface. The “AM: add movie” and “LM: list movies” options in the menu-based interface should also work. In other words if you type AM and then, when prompted, type the name of a movie, you should then find that, when you type LM, the name of this movie appears in the list that is displayed. You should check that your code works by executing the tests that are set out at the end of this document.

Test Plan for Part 1

You should test your implementation of part 1 by adding two movies to the database and checking that they are added to the database. You should do this both in the graphical interface, checking that the movies have been added by looking at the list in the top left hand of the screen, and also in the menu-based interface, checking that they are added by typing the “LM” option. You should document your tests as by submitting a table that is exactly in the form set out below, writing the words YES or NO in the right hand columns to indicate whether the tests have been passed. See image.

What you have to do for Part 2

For part 2 you need to do two things Firstly you should implement an Actor class. This class should have the following constructors and Methods

  • public Actor(String firstName, String lastName) This constructs an object representing the actor with the first and last names supplied.
  • public String getFirstName() returns the first name of the actor.
  • public String getLastName() returns the last name of the actor.
  • public String getFullName() returns the full name of the actor. The full name is the first name, followed by a space, followed by the last name.

Example of use The following code See image.

Would produce the output Orson Welles Orson Welles,

Secondly you should implement the methods addActor, getNbrActors, getActor, getActorFirstName, and getActorLastName in the MovieBase class. The way in which these methods should work is described by the comments in the skeleton MovieBase class that we have given to you. The String returned by the getActor method should be the full name of the actor, as returned by the getFullName method in the Actor class.

If you implement these methods correctly then you should find that you can add actors to the database using either the GUI or console versions of the application (i.e. by running either GUIMain or Main). To add an actor using the GUI version of the program, just type the first and last names into the text fields next to the Add Actor button and then click on that button. You should see the actor’s name appear in the list in the top right of the screen ) To add an actor using the console version use the AA option (and then check that they really were added using the LA option.

Test Plan for Part 2

You should test your implementation of part 1 by adding two movies to the database and checking that they are added to the database. You should do this both in the graphical interface, checking that the movies have been added by looking at the list in the top left hand of the screen, and also in the menu-based interface, checking that they are added by typing the “LM” option.

You should document your tests as by submitting a table that is exactly in the form set out below, writing the words YES or NO in the right hand columns to indicate whether the tests have been passed. See image.

What you have to do for Part 3

For part 3 you need to modify your program so that it can keep track of which actors have appeared in which films. You may assume that there will never be more than 100 actors in the database, and that there will never be more than 100 movies.

In order to do this you must implement the following methods in the MovieBase class.

  • public boolean addActorToMovie(String movieName, String firstName,String lastName) This method adds the actor with the specified first and last names to the movie with the specified movie name. The movie and actor must already have been added to the database and the actor must not have been previously added to the cast. If these conditions are not met then the method should do nothing and return false. If they are met then the actor is added to the cast and the method returns true .
  • public int getNbrActorsForMovie(String movieName) This method returns the number of actors for the specified movie. If the movie is not present in the database it should return 0.
  • public String getActorForMovie(String movieName, int i) This method returns the full name of i’th actor in the cast for the specified movie. The indexes start at 0. If the movie is not present in the database then the method should return null.
  • public int getNbrMoviesForActor(String firstName, String lastName) This method returns the number of movies that have the specified actor in their cast. If the actor is not present in the database then it should return 0.
  • public String getMovieForActor(String firstName, String lastName, int i) This method returns the name of i’th movie that has the specified actor in its cast. If the actor is not present in the database then the method should return null.

Example of use If you were to run the following code See image.

The output would be See image.

What Will You See If You Get This To Work?

If you correctly implement the methods mentioned above then you should find that you can add actors to movies using either the GUI version of the program or the console application. To add an actor to the cast of a movie using the GUI program, select the Movie in the movies pane (top right) and the actor in the Actors pane (top left), and then click on the “Add Actor To Cast” button. If you select a Movie then its cast will be displayed in the “Movie Details” pane. If you selecting an Actor then a list of the films in which he/she has appeared will be displayed in the “Actor Details” pane (see Figure 1).

Figure 1 Cast and Film List See image.

To add an actor to the cast of a movie using the console program, select the “AC” option. To view the cast of a movie use the “LAM” option. To view the list of movies in which an actor has appeared, use the “LMA” option. If you have implemented the above methods correctly then all of these methods should work.

How Do You Do This?

There is more than one way to implement the methods described above. However it is likely that you will also need to add methods and attributes to the Actor and Movie classes. It is also likely that you will need to add methods to the MovieBase class that are not in the list given above, but which are needed in order to get those methods to work.

Test Plan for Part 3

You should test your implementation of part 3 by performing the following tests. You should document your tests as by submitting a table that is exactly in the form set out below, writing the words YES or NO in the right hand columns to indicate whether the tests have been passed. See image.

In part four you are required to save and load the lists of movies and actors, but not the links between them (that is to say you do not need to save the cast lists and filmographies). In part five you will be required to save the cast lists and filmographies as well.

What you have to do for Part 4

In order to save and load the database you need to implement the following methods in the MovieBase class

  • public void save(String fileName) throws FileNotFoundException This method should save the actor and movie lists into a single text file, whose name is given by the String filename. It is up to you to decide exactly how to translate the two lists into lines of text.
  • public void load(String fileName) throws FileNotFoundException This method should load the actor and movie lists from a single text file, whose name is given by the String filename. The format of the file should be the same as the one you decided on when you implemented the save method. In other words, if you save a file, quit the application, then run the application and load the file then you should get the original movie and actor lists back (but not the cast lists and filmographies).

What Will You See If You Get This To Work?

If you correctly implement the methods mentioned above then you should find that the “save” and “load” buttons in the GUI application work (to the extent that you can save and load movie lists and actors – cast lists and filmographies will not work). When you click on these buttons you should find that a dialog window is displayed that allows you to select the file that you want to save or load. There is no default extension for these files, so you can choose your own extension (.dat for example, or .txt).

You should find that the “L” and “S” options in the console application also allow you to save and load files. These options ask you to type in the name of the file. By default the program will try to find the file in same directory as the NetBeans project. If you want it to go into any other directory then you can type in the complete pathname, for instance C:\Documents and Settings\p0073862\Desktop\myfile.dat

How Do You Do This?

You will need to decide on a format for the text files that you create, in other words you need to decide how to translate the information in the database into lines of text. There is more than one way to do this and you can choose anything that works and that is reasonably sensible.

Test Plan for Part 4

You should test your implementation of part 4 by rerunning all of the tests for part 3, and adding the following tests (on both the GUI and menu-based applications).

  • Create an empty database and save it to a text file. Then quit the application. Then restart the application and load up your text file. The expected result is that no error messages should be displayed and, after you have loaded the file you should have a completely empty database.
  • Perform the actions set out in the test plan for part 3, and then save the resulting database to a text file. Then quit the application, restart it and load up the text file you just displayed. The expected result is that no error messages are displayed, that the movie and actor lists are identical to those that were in the database when the file was saved, but that cast lists and filmographies are not preserved.

You should document your test in a table with the same format as that used for part 3, but with the above two tests added in. In part five you will be required to save and load the cast lists and filmographies as well.

What you have to do for Part 5

You will need to modify the format of the text files created when you save the database so that you represent cast lists and filmographies as well as lists of actors and movies. There is more than one way of doing this, and you are free to choose anything that works and which is reasonably sensible. You then need to modify the save and load methods that you implemented in the previous part, so that they work with the revised file format.

What Will You See If You Get This To Work?

If you correctly implement the methods mentioned above then you should find that the “save” and “load” buttons in the GUI application work correctly, and that cast lists and filmographies are saved and restored, as well as movie and actor lists. You should find that the “L” and “S” options in the console application also allow you to save and load files correctly.

Test Plan for Part 5

The test plan for part 5 is identical to that for part 4, except that when you run the final test (the one in which you save the database, quit and restart the application, and then reload the database) you need to check that cast lists and filmographies are also restored. The notes that we made regarding testing of part 4 also apply to part 5. Specifically…

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.