Assignment II



Assignment II

Due July 5, 2005

Introduction

For this assignment, you must implement a graphical user interface in Java that allows to visualize a main library of songs, and create a play list from it.

1 Song (30 marks)

Create a class Song with the following characteristics:

• A Song has a name, an artist and an album (all three of type String for example);

• A Song has three access methods: getName(), getArtist() and getAlbum(). None of the instance methods of the class Song can change the content (state) of the object -- a Song object is immutable. This property will facilitate sharing the songs in between play lists;

• The name of the Song, the artist and the album cannot be null or the empty String. An exception of type IllegalArgumentException must be thrown if an invalid parameter is given;

• Finally, a Song should also have the methods String toString() and boolean equals( Object other).

2 SortByName, SortByArtist and SortByAlbum (15 marks)

The interface java.parator declares a method for comparing two objects: int compare( Object a, Object b ). Implement the following three comparators.

• SortByName is a class that implements the interface Comparator. Its method int compare( Object a, Object b ) returns a negative number if the name of the Song designated by a comes before the name of the Song designated by b in the alphabetical order. It returns zero if the names are equals and a positive number otherwise. It throws a ClassCastException if the arguments’ types prevent them from being compared by this Comparator;

• SortByArtist is a class that implements the interface Comparator. Its method int compare( Object a, Object b ) returns a negative number if the artist of the Song designated by a comes before the artist of the Song designated by b in the alphabetical order. It returns zero if the artists are equals and a positive number otherwise. It throws a ClassCastException if the arguments’ types prevent them from being compared by this Comparator;

• SortByAlbum is a class that implements the interface Comparator. Its method int compare( Object a, Object b ) returns a negative number if the album of the Song designated by a comes before the album of the Song designated by b in the alphabetical order. It returns zero if the albums are equals and a positive number otherwise. It throws a ClassCastException if the arguments’ types prevent them from being compared by this Comparator.

3 PlayList (30 marks)

A PlayList is a specific data structure that has the following characteristics.

• Can store an unlimited number of number of songs. It is up to you to decide what should be the initial capacity. You have to have a default constructor without parameters;

• int getSize() returns the number of songs that are currently stored in the PlayList;

• boolean addSong( Song song ) appends the specified song to the end of this PlayList. Ensures that this PlayList contains the specified Song. Returns true if this PlayList changed as a result of the call. Returns false if this PlayList already contains the specified Song. Throws an exception of type IllegalArgumentException if song is null;

• Song getSongAt( int index ) returns the song found at position index of the PlayList. The first element is stored at position 0. It throws an exception of type IndexOutOfBoundsException if the index is out of range;

• void sort( java.parator c) sorts the PlayList according to the order induced by the specified comparator.

4 PlayListManager (25 marks)

The class PlayListManager implements the graphical user interface of the application. It must support at least the following operations.

• The constructor PlayListManager( PlayList library ) receives a reference the main library of songs;

• It displays all the songs of the main library;

• It allows to create a new (empty) PlayList;

• It allows to copy songs from the main library to the new PlayList (the songs should not be removed from the main library);

• It allows to visualise the new PlayList;

• Both PlayLists (the main library and the new one) can be sorted by name, by artist and by album;

• Prints (on screen) the content of the new play list;

• Provides a convenient way to exit the application.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download