For each of the following problems, write up your answers on paper (or use a word processor). Remember that the answers you write or type MUST be your own.
Use the phone directory program discussed in class to answer problems 1-4.
public int find(int[] data, int target) { // code not shown }
List a set of test conditions to use to test this method as completely as possible.
A DVD movie consists of a title, a rating (e.g. PG, R, etc.), and a running time in minutes.
In this project, you will create an application to allow the user to maintain a collection of DVD movies using an array.
When the application starts up, it will read in the DVD data from a text file to initialize the array, if the file is available. If the file is not there, then the program starts with an empty array. If the file is corrupted (has an invalid or missing value), then the program stops its initialization at the point of the error. The data file should contain one DVD per line, with title followed by rating followed by running time in minutes, all separated by commas. You may assume titles are all in uppercase and do not contain commas. For example:
ANGELS AND DEMONS,PG-13,138 STAR TREK,R,127 UP,PG,96
The titles may not be in alphabetical order, but the DVDs should be inserted into the array in alphabetical order.
The application will then allow its user to perform the following operations:
Your assignment is to complete the first two classes (DVD and DVDCollection) to create a correctly functioning application.
Complete the DVD class by completing the given methods (constructor, accessors and mutators). Add javadoc comments so you can generate a javadoc documentation file showing how to use this class.
The DVDCollection class uses an array to maintain the collection of DVDs. The DVDs should be stored in alphabetical order based on title starting at position 0 in the array, using adjacent cells. All titles should be stored in uppercase only and are assumed to be unique (no duplicates). You may assume titles do not contain commas. Complete the following methods in the DVDCollection class in the order shown below and test each one before moving on.
toString - returns a string containing all of the DVDs in the collection, separated by newlines characters, along with the value of numdvds and the length of the DVD array for debugging purposes. The string should be formatted as shown in the example below:
numdvds = 3 dvdArray.length = 7 dvdArray[0] = ANGELS AND DEMONS/PG-13/138min dvdArray[1] = STAR TREK/R/127min dvdArray[2] = UP/PG/96min
addOrModifyDVD - given the title, rating and running time of a DVD, add this DVD to the collection if the title is not present in the DVD collection or modify the DVD's rating and running time if the title is present in the collection. Do this operation only if the rating and running time are valid. If a new DVD is added to this collection, insert the DVD so that all DVDs are in alphabetical order by title. (NOTE: The collection should already be in alphabetical order when this method is called since this is the only method available to insert DVDs.)
removeDVD - given the title, this method should remove the DVD with this title from the collection if present. The title must match exactly (in uppercase). If no title matches, do not change the collection.
getDVDsByRating - given the rating, this method should return a string containing all DVDs that match the given rating in the order that they appear in the collection, separated by newlines.
getTotalRunningTime - this method should return the total running time of all DVDs in the collection. If there are no DVDs in the collection, return 0.
loadData - given a file name, this method should try to open this file and read the DVD data contained inside to create an initial alphabetized DVD collection. HINT: Read each set of three values (title, rating, running time) and use the addOrModifyDVD method above to insert it into the collection. If the file cannot be found, start with an empty array for your collection. If the data in the file is corrupted, stop initializing the collection at the point of corruption.
save - save the DVDs currently in the array into the same file specified during the load operation, overwriting whatever data was originally there.
Do not try to write all of these methods before testing your program. Instead, write the first two methods (and any associated helper methods) and test your program. Once you feel your program is tested enough, then move on to the other methods, one by one. Do the file input/output methods last. This way, if they don't work correctly, you can always go back to the previous version and hand in something that works correctly without using files, rather than hand in something that does not work at all.
Include documentation with all of your code. Your documentation should conform to the javadoc format when specified. One point of the ten points for this program will be based on the quality and form of your documentation.
Additionally, you may not change any code given to you already. That is, do not alter the methods so that your methods will work. You should be able to complete the assignment starting from the code given to you.
Using the data file given to you, run the program in console mode and capture the output of a sample run as a text file (cut and paste from the console window). Save this file in your submission as samplerun.txt. The file should illustrate your test cases that you used to test the correctness of the methods in the DVDCollection class. This file will also be worth 1 point of your program grade.
See the course website for instructions on how to hand in your program and the policy for late submissions.