package lab12; import java.util.Collections; import java.util.List; import java.util.ArrayList; import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Lab12 { /** * This method uses Bubble-Sort to sort the specified List of CatalogItems. * @param the ID type for each CatalogItem in catalogs over which CatalogItems are * ultimately sorted * @param the Media type which each CatalogItem in catalogs contains * @param catalog the List of CatalogItems to sort */ public static, S extends Media> void sort( List> catalog ) { int j; for( int i = 1; i < catalog.size(); i++ ) { j = i; while( j > 0 && catalog.get( j - 1 ).compareTo( catalog.get( j ) ) > 0 ) { Collections.swap( catalog, j, j - 1 ); j--; } } } public static void main( String[] args ) { //Create an ArrayList of CatalogItems named iPod //This ArrayList must take a type parameter of CatalogItem //CatalogItem in turn should take type parameters of Integer and CD //---here---- //adding CatalogItems iPod.add( new CatalogItem( 0, new CD( "Lady Gaga", "The Fame", 2008 ) ) ); iPod.add( new CatalogItem( 7, new CD( "Lady Gaga", "The Fame Monster", 2009 ) ) ); iPod.add( new CatalogItem( 5, new CD( "Jay-Z", "The Blueprint 3", 2009 ) ) ); iPod.add( new CatalogItem( 2, new CD( "Santana", "Supernatural", 1999 ) ) ); //printing the iPod catalog before and after sorting System.out.println( "iPod Catalog:" ); System.out.println( "Before Sorting:" ); System.out.println( iPod ); sort( iPod ); System.out.println( "\nAfter Sorting by ID:" ); System.out.println( iPod ); //Create an ArrayList of CatalogItems named kindle //This ArrayList must take a type parameter of CatalogItem //CatalogItem in turn should take type parameters of String and Book //---here----- //Add elements to kindle by creating a text file and reading it //Each line of the file should contain one field-- String-ID, author name, title, and year //See the iPod code above for guidance try { //---Create a Scanner object here for reading your file---- while( fileScanner.hasNextLine() ) { //---add a single CatalogItem here---- } } catch( FileNotFoundException e ) { System.out.println( "Unable to locate: " + e.getMessage() ); } //printing the kindle catalog before and after sorting System.out.println( "\n\nKindle Catalog:" ); System.out.println( "Before Sorting:" ); System.out.println( kindle ); sort( kindle ); System.out.println( "\nAfter Sorting by ID:" ); System.out.println( kindle ); } }