编程辅导 C C++ Java Python MIPS Processing 网络家教 在线辅导

编程家教 远程写代码 Debug 讲解答疑 课后答疑 不是中介,本人直接答疑

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

 SOFTENG 251 Object Oriented Software Construction

Assignment 2: Personal Movie Database (PMDB)Due: 24th April (end of lab)April 1st, 2008IntroductionLet’s say you are writing a simple desktop application for maintaining information about moviesand movie-related people, i.e. cast and crew, in a manner similar to the movie databases on theweb such as www.imdb.com and www.allmovies.com. The application, which you decide to callPersonal Movie Database (PMDB), manages a collection of items, each containing informationabout either films or people, and supports operations for listing, adding, removing, sorting andsearching these items. Of course, being a “database” (although not in the strict sense), theprogram also supports persisting the collection of items onto a file and loading from it afterwards.For this assignment, you are provided with a basic skeleton code for the program, downloadablefrom the Assignments section of the course page, and your job is to complete the necessary bitsof the program as indicated by the tasks explained later.You are provided with two additional components to the Movie Database:• A set of JUnit tests for ensuring the code for your Movie Database is completed correctly.The tests are complete, so you are not required to add further tests of your own, althoughyou are most welcome to.• A Movie Browser, which is a graphical user interface (GUI) to your Movie Database allowingusers to interactively look up and search the information, as shown in figure 1. You do notneed to modify its code. The Browser not only adds a “coolness” value to your MovieDatabase but also acts as a secondary mechanism for visually “testing” your Database.This assignment will get you to utilise of a variety of classes from the java Collections frameworkand also to create reusable, flexible methods and classes with the help of Generics.Figure 1: The Browser after you successfully complete your Movie Database1Figure 2: An overview of the elements of Movie DatabaseDetails of PMDBThe program you will be working on is of a considerably larger scale than in the previous assign-ment. However, do not feel overwhelmed by this, as the actual number of classes you need to workon is reasonably small. In fact a significant portion of the program is dedicated to the Browser,the details of which you do not have to worry about, and the unit tests, which you are encouragedto study but not required to modify.Figure 2 shows the structure of your Personal Movie Database (PMDB) at a glance. You cansee that it has three main packages: movies.core (1), movies.gui (2) and movies.tests (3).1. Classes in the movies.core package make up the core Movie Database. Class Person con-tains basic attributes of a movie-related person including name, date of birth and biography.Class Movie has basic attributes for a film, including title and year of release. It should alsostore information about cast and crew by making references to Person objects: you haveto implement this in Task 4. Class MovieDatabase stores all Movie and Person objects intheir respective Lists, providing operations (i.e. methods) for listing, adding and remov-ing movies and people, which you are to complete through Task 1. Class Sorter definesmethods for sorting any given List of movies or people by different attributes: this you areto implement through Task 2 and Task 3. MovieDatabase defines further operations forsearching movies and people according to various kinds of customisable criteria, representedby the interface SearchCriterion: this will become clearer as you tackle Task 5.2. The movies.gui package, along with its many subpackages, contains all classes comprisingthe graphical Movie Browser. Again, you do not need to understand the classes in thispackage. All you need to know is that the Browser can be launched by running the classMovieBrowser.3. The package movies.tests contains all unit tests divided effectively into two test suites: theessential tests (movies.tests.essential subpackage) and the optional tests (movies.tests.optional subpackage). The essential tests are the ones that must be passed when you havecompleted all of the basic tasks (1 to 5). The optional tests on the other hand are designedto validate the optional tasks (6 and 7), should you choose to do them. Thus if you’re notdoing them, then it does not matter whether any of these tests passes.For more details on the individual classes contained in the above packages, consult the Javadoc(Java documentation) pages available on the Assignments section of the course web page. You canalternatively read the comments within the Java source files for these classes — you get the sameinformation either way (the Javadoc webpages were automatically generated from these commentsthrough the Javadoc tool. Neat huh?).2Assessment Criteria1. Functional correctness — your program passes all provided unit tests, and the Browserfunctions properly to reflect this.2. Strong evidence of effort to 1) apply good object-oriented programming techniques, suchas using inheritance and polymorphism when appropriate; and to 2) reuse as much of theavailable code as possible — i.e. avoid reinventing the wheel — both from the Java standardlibrary and from within your own program.3. Demonstration of a thorough understanding of your own work by being able to answerquestions from the lecturer or the tutors.TasksIt is strongly recommended that you complete the following tasks in order. Associated with eachtask is a test case that must pass on completion. In the end, if all of the essential test cases(i.e. from the movies.tests.essential package) pass, then you can be fairly confident yourimplementation is correct. You are encouraged to look at the test cases and study what exactlyis being tested to better understand the requirements of your program.Obviously, initially most of the tests will fail. However, as you successfully complete each task,you will find your test cases passing one by one. Similarly, the Movie Browser will initially notfunction properly, but as you tackle each task you will see the appropriate changes being reflectedin the Browser.Task 1 Add/Delete Movies and PeopleUnder the class MovieDatabase, complete the methods addPerson(), deletePerson(), addMovie()and deleteMovie(), which should be self-explanatory. Read the Javadocs for each of these meth-ods for details on parameters and required return values.After you successfully complete this task:• TestAddDeleteListMoviesAndPeople should pass.• The Browser should correctly display a list of movies and people as you can see in the tableson the left-hand side of the windows in figure 1.Task 2 Define natural ordering for PersonAs discussed in lectures, one way to allow objects of a particular type to be sorted is to define anatural ordering of the type, by making the type implement the interface java.lang.Comparable.You need to define the natural ordering for Person, which has been made to implement Comparable,where the method compareTo() is left for you to complete. Basically, the natural ordering betweenany two people is determined by comparing their last names first, followed by their first names andlastly date of birth. Read the Javadoc for this method for the exact details on how the orderingis determined.After you successfully complete this task:• TestPersonBasics should pass.• In the Browser, you should be able to sort people according to their natural ordering. To dothis, switch to “People View” (refer to window on the right in figure 1), then click on thetable header called “Last name”.3Task 3 Sort Movies and PeopleAnother way to allow objects to be sorted is to define a Comparator (from java.util) for theobjects’ type, as discussed in lectures. The advantage to using Comparators is that the same typecan be ordered in many different ways. Thus, for example, to be able to sort Person objects byfirst name instead of last name, you can write your own Comparator implementation to comparepeople by their first names. To perform the actual sorting, the class Collections (also fromjava.util) provides the method sort() that takes in a List and Comparator as argument.You need to flesh out the Sorter class by completing the methods sortMoviesByTitle(),sortMoviesByYear(), sortPeopleByFirstName() and sortPeopleByLastName() in order to sortmovies by title or by year, and sort people by first name or by last name, respectively. Each methodtakes in two parameters: the first being the actual list to sort, and the second being a booleanindicating whether the sorting should be done in ascending or descending order. By default, theCollections.sort()method sorts in ascending order, so you need a way to reverse the operationas well. The methods reverse() and reverseOrder() may prove useful.After you successfully complete this task:• TestSort should pass.• In the Browser, you should now be able to sort by all four attributes “Title”, “Year”, “Firstname” and “Last name” — by clicking on the corresponding table headers. Each successiveclick will toggle between ascending and descending sort.Task 4 Associate cast and crew with a MovieModify Movie so that it stores cast and crew information.• A movie has a set of characters, each played by a single actor (Person). It is possible forseveral characters to be played by the same actor.• A movie has a set of crew roles (e.g. director, writer, producer), each filled by a singlecrew member (Person). Again, it is possible for several roles to be filled by the same crewmember, but only one person can fill each role. Notice this is a slight simplification of thereal world, as it makes more sense for multiple people to be involved in a single role: youcan do this by completing the Optional Task 6.Complete the following methods: addCharacter(), getActorPlaying(), removeCharacter(),getActors(), getCharacters(), addCrewRole(), getCrewMemberFor() and removeCrewRole().You can find the details for what each of these methods should do along with explanations ofparameters and return value in the methods’ Javadoc comments. You may consider using aHashMap or a TreeMap to store the mappings from characters to actors, and likewise from roles tocrew members.Note that the Collection of People and String objects returned from methods getCharacters()and getActors() must be sorted according to the natural ordering of the respective objects. Youmay consider returning a TreeSet, which automatically ensures all of its items are sorted.After you successfully complete this task:• TestCastCrew should pass.• The Browser should display, on the right hand side, the cast and crew list for each selectedmovie while you’re in “Movies View” (see figure 1). Note however that for each crew rolethere would only be at most one crew member listed.4Task 5 Search Movies and PeopleComplete MovieDatabase to allow a list of movies or people to be searched according to a givensearch criterion, for example “movies released in the year 2000” or “people with the last nameCoppola”. The search criterion can literally be anything, so you wouldn’t want to have to duplicatethe searching logic for every criterion you want to specify. Instead what you do is separate thebasic searching logic from the individual search criteria. For any criterion, the basic searchinglogic is always:go through each item of a given list {if item satisfies a given criterion then add it to the results}return resultsThus the idea is to have a single generic method for handling the searching, to which you can“plug in” any kind of search criterion. The method genericSearch() has been defined for thispurpose, which you have to complete. This method should be able to take in a list of items (ofany type) and a search criterion, and return a new list containing only the items satisfying thegiven criterion. The search criterion can be anything as long as it implements the generic interfaceSearchCriterion, which defines a single method accept() that should return true if the given item matches the criterion. The type parameter T refers to the type of the item to evaluate, for example Person or Movie. You will see that three implementations of SearchCriterion are provided: • PersonNameCriterion evaluates whether a person has a certain first name and/or last name. • MovieTitleCriterion evaluates whether a movie has a certain title. • MovieYearCriterion evaluates whether a movie was released during a certain year range. You need to flesh out each of the above classes. Read their Javadocs for a full specification on what they are supposed to match. You are invited to come up with your own search criteria in addition to these three — see Optional Task 8. After you successfully complete this task: • TestSearch should pass. • You should be able to search movies by title and year and search people by name through the Browser using the “Search” Button. Each time a search is made, a new tab is created under which the search results are displayed, as you see on the left window in figure 1. The tab can be closed afterwards by double-clicking on it. 5 Optional Tasks The following tasks are optional. The Movie Browser will become fully operational when you complete them. Optional Task 6 Many crew members to many roles Modify Movie such that it allows multiple crew members to be associated with a single role. In other words enable a many-to-many relationship between roles and crew members. The methods addCrewMember(), removeCrewMember() and getAllCrewMembersFor() are meant to accommo- date this extended relationship. Initially, they simply delegate to the methods you completed in Task 4, so you need to change them. There are several ways in which you can implement a many-to-many relationship. For instance: • You can define a Map that maps from a role to a Set of people. To associate a role to a new crew member you would first get the set of people associated with the role and then add the new crew member to the set. • You can define a Set that holds a collection of 

相关推荐