CSU Banner

CS 163/164, Fall 2016

Lab 13b - Music Library (Part 2)

Wed-Fri, Oct. 19-21, 2016


Objectives of this Lab

Description

Continue implementing the music library project from the previous lab.

Part Four

  1. Implement a public static method writeLibrary in the Library class that takes a String parameter with the output filename, as follows:
        public static void writeLibrary(String outputFile);
        
  2. Call writeLibrary from your main (after readLibrary) with args[1] as the parameter.
  3. Do not hard-code the file name, use the name passed in as a parameter.
  4. To implement writeLibrary, open a PrintWriter and copy the code from main that iterates the array of Music objects. You should get the same output as in the previous lab, except the method will send the output to a file.
    1: Brown Eyed Girl, Blowin' Your Mind!, Van Morrison, 1967
    2: Stop Putting the Hurt on Me, Lucille, B. B. King, 1968
    3: Another Brick in the Wall, The Wall, Pink Floyd, 1979
    4: Funeral for a Friend, Goodbye Yellow Brick Road, Elton John, 1973
    5: Beat It, Thriller, Michael Jackson, 1982
    6: Like a Virgin, Like a Virgin, Madonna, 1984
    7: So Far Away, Brothers in Arms, Dire Straits, 1985
    8: Try a Little Tenderness, Swamp Boogie Queen, Katie Webster, 1990
    9: Hey Jack Kerouac, MTV Unplugged, 10,000 Maniacs, 1993
    10: Mockingbird, Encore, Eminem, 2005
    11: Jackdaw, Draw the Line, David Gray, 2009
    12: Someone Like You, 21, Adele, 2011
    Number of Tracks: 12
    Total cost: $13.78
        
  5. Your output file should match this exactly.
  6. The format above has a number for each title, starting at 1 and ending at the last number. Each field is separated by a comma and space, but there is no trailing comma or space.
  7. Make sure that your program correctly writes all of the data in the input file to the output file.
  8. Add code to writeLibrary figure out how much it would cost to buy all the titles in the file by iterating the array of Music objects and calling getPrice for each element. You must accumulate the total cost in a variable. Write the message below to the output file using PrintWriter.printf() to ensure 2 digits after the decimal point in the total cost.

Part Five

  1. Implement a public static method searchTitles in the Library class that takes a String parameter and prints all the tracks that contain that String.
        public static void searchTitles(String search);
        
  2. This method will print in the same format as before, but will only print the titles containing the search string. Do NOT print the number of tracks or total cost!

Part Six

  1. Implement a public static method sortTitles in the Library class that sorts the array of in the Library by title. You will do this by iterating the library for each uppercase letter, and printing only the titles that start with that letter. Note that the resulting output is sorted only by the first letter, and is not completely alphabetized.
        public static void sortTitles();
        
  2. This method will print in the same format as before, but will only print all the titles in the sorted order. Do NOT print the number of tracks or total cost!

Testing

NOTE: Test your code by running it on the input file and checking the output file. To really ensure your program is correct, create another test file with the same format as music.txt, but a different number of titles and different data.

Submissions

To create the Library.jar file containing Library.java and Music.java, you must export the project from Eclipse in the JAR format. The default in Eclipse is to make a JAR with Library.class and Music.class. This will not pass automated grading. To avoid this and correctly submit the source files, follow these directions: Export Java source files with Eclipse.


Follow directions from the instructor to package your source files into Library.jar, and submit it to the R13 assignment Checkin tab on the course web site. Automated grading will be running.


CS Banner
CS Building