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.
find the file Cwk2Skel.zip. If you unzip this file you should find that you have a NetBeans project containing the following java files.
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.
For part 1 you should:
Here is a brief description of what these constructors and methods should actually do.
Movie class methods and constructor:
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:
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.
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.
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
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.
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.
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.
Example of use If you were to run the following code See image.
The output would be See image.
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.
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.
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.
In order to save and load the database you need to implement the following methods in the MovieBase class
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
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.
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).
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.
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.
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.
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…