Question: Instructions Start NetBeans. Create a new project called Lab6. Create a Java main class file using the class name YourlastnameLab6 with your actual last name.

Instructions

  1. Start NetBeans.
  2. Create a new project called Lab6.
  3. Create a Java main class file using the class name YourlastnameLab6 with your actual last name.
  4. Create a Java class file for a Record class.
  5. Implement the Record class.
    1. Add the following private instance variables to the Record class:
      • A String representing the title of the record.
      • A String representing the record artist.
      • An int representing the year the record was released.
    2. Add a constructor that takes two Strings and an int and uses them to initialize the Record object. This class will not have a default constructor.
    3. Add an accessor method for each private instance variable. Mutators will not be necessary.
    4. Add a void method called display that displays the record information in the following format:
    1. - Artist (YearReleased)
    1. example, the record Unknown Pleasures by Joy Division, released would be displayed as:
    2. Pleasures Joy Division (1979)
    1. Add a boolean method called comesBefore that takes a Record object as a parameter and compares the Record the method was called on (this) with the Record passed as a parameter (record).
      • If the artist of this comes before the artist of record alphabetically, return true. Use the compareToIgnoreCase method of the String class to determine this.
      • If the record artists are the same, and the year this was released is earlier than the year record was released, return true.
      • Otherwise return false.
  1. Add a unit test for the Record class to your main class.
    1. Write a static void method called testComesBefore that takes two Record objects as parameters and uses the comesBefore method to compare them.
    2. In the main method, create some Record objects and use testComesBefore to test three cases:
      • The two records have different artists and the first one comes alphabetically before the second.
      • The two records have the same artist and the first one was released before the second.
      • The first record comes after the second record.
    3. Run the program to see if comesBefore works correctly.
    4. The output of the tests should look something like this:
    1. comesBefore: Unknown Pleasures comes before Closer comesBefore: New Day Rising comes before Unknown Pleasures comesBefore: Closer does not come before Disintegration
  1. Create a Java class file for a RecordCollection class.
  2. Implement the RecordCollection class.
    1. Add the following private instance variables to the RecordCollection class:
      • An int representing the number of records in the record collection.
      • An array of Record objects, representing the records in the collection.
    2. Add a constructor for the RecordCollection class that takes an int representing the maximum number of records as a parameter and does the following:
      • Initializes the number of records to zero.
      • Initializes the array so its length is the maximum number of records.
    3. Add a public accessor method for the number of records.
    4. Add a method called display that displays all of the records in the collection. If there are no records in the collection, display the following:
    1. records in the collection
  1. Add a unit test for the display method of the RecordCollection class to your main class.
    1. Write a static void method called testRCDisplay that takes a RecordCollection as a parameter, calls display on it, uses getNumRecords to get the number of records in the collection, and displays that as well.
    2. Add code to the main function to create a RecordCollection object and pass it to textRCDisplay.
    3. Run the program to see if display works correctly.
    4. The output of the test should look something like this:
    1. display: No records in the collection Number of records: 0
  1. Implement a boolean method called addRecord to the RecordCollection that does the following:
    1. The method should take a Record as a parameter.
    2. If the record is null or the array is full return false.
    3. Otherwise, add the record to the next open spot, increment the number of records, and return true.
  2. Add a unit test for the addRecord method to your main class.
    1. Write a static void method called testAddRecord that takes a RecordCollection and a Record as parameters, uses the addRecord to add the record to the collection, displays the collection, and displays the number of records in the collection.
    2. Add code in the main function to call testAddRecord several times to add several Record objects.
    3. Run your program to see if the addRecord method works correctly.
    4. The output should look something like this:
    1. addRecord Adding Unknown Pleasures - Joy Division (1979) Collection: Unknown Pleasures - Joy Division (1979) Number of records: 1 addRecord Adding Closer - Joy Division (1980) Collection: Unknown Pleasures - Joy Division (1979) Closer - Joy Division (1980) Number of records: 2 addRecord Adding Disintegration - Cure, the (1989) Collection: Unknown Pleasures - Joy Division (1979) Closer - Joy Division (1980) Disintegration - Cure, the (1989) Number of records: 3 addRecord Adding New Day Rising - Husker Du (1985) Collection: Unknown Pleasures - Joy Division (1979) Closer - Joy Division (1980) Disintegration - Cure, the (1989) New Day Rising - Husker Du (1985) Number of records: 4
  1. Implement a method called findRecord to the RecordCollection class that does the following:
    1. The method should take a String representing a title and a String representing an artist as parameters.
    2. Start at the beginning of the array.
    3. Loop until the record with the given title and artist is found or the end of the array is reached.
    4. If a record is found, return it.
    5. Otherwise return null
  2. Add a unit test for the findRecord method to your main class.
    1. Write a static void method called testFindRecord that takes a RecordCollection, and two String objects representing a title and an artist.
    2. The method should display the title and artist, then use the findRecord method to try to find a record with those attributes.
    3. Add calls to testFindRecord to the main function to test the following cases:
      • Use the title and artist of a record in the collection.
      • Use the title and artist of a record not in the collection.
    4. Run your program to see if the findRecord method works correctly.
    5. The output should look something like this:
    1. findRecord Title: New Day Rising Artist: Husker Du Found: New Day Rising - Husker Du (1985) findRecord Title: Nevermind Artist: Nirvana Record not found
  1. Implement a void method called sortRecords to the RecordCollection class that does the following:
    1. Perform a selection sort to sort the records in the array.
    2. Use the comesBefore method to determine if one record is smaller than another record.
    3. Make sure only to search the locations that have valid entries.
  2. Add a unit test for the sortRecords method to your main class.
    1. Write a static void method called testSortRecords that takes a RecordCollection, calls the sortRecords method, and displays the collection.
    2. Add a call to testSortRecords to your main method.
    3. Run your program to see if the sortRecords method works correctly.
    4. The output should look something like this:
    1. sortRecords Disintegration - Cure, the (1989) New Day Rising - Husker Du (1985) Unknown Pleasures - Joy Division (1979) Closer - Joy Division (1980)
  1. Hand in the source files, YourlastnameLab6.java, Record.java, and RecordCollection.java to the D2L assignment dropbox called Lab 6. The comments in each file should contain your name, CSCI 2011 Lab 6, and a description of what the class defined in the file does.

**PLEASE MAKE SURE IT RUNS PROPERLY, GIVING THE DESIRED OUTPUT, AND THAT THE CODE IS WHAT THE ASSIGNMENT ASKS FOR. THANK YOU**

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!