Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
Java Language EssentialsDownload tutorial zip fileEmail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
Exercises
  


10. MusicStore: Adding Titles: Help page 30 of 31




  • Task 1

    Create the user-defined data type MusicTitle with two String instance variables, title and artist, initialized to a "noname"-type of value to enhance debugging. Implement get and set access methods for both instance variables.


    This class is very simple. It should reside in the same directory as MusicStore and TestMusicStore.

  • Task 2

    Add the instance variable titles of type MusicTitle[] to MusicStore, initialized to null, and then implement the access methods setTitles() and getTitles().


    Note that getTitles() does not process the individual array elements; it simply returns the reference for the titles instance variable. setTitles() should take a MusicTitle array, that is, data type MusicTitle[], as an argument. getTitles() should return the reference to the instance variable for the array.

  • Task 3

    Add a displayMusicTitles() method to MusicStore that traverses the array of titles and displays the title-artist data.


    This method is similar to displayDiet() from the course notes.

  • Task 4

    Modify TestMusicStore to test/display the functionality of MusicStore's displayMusicTitles() method.


    You should create two or more instances of MusicTitle and store the references to these instances as array elements.

  • Task 5

    Compile the source code for MusicStore and TestMusicStore.


    Some Java environments require a CLASSPATH setting. You should set the CLASSPATH environment variable to include the current directory, but only if your environment requires CLASSPATH.

  • Task 6

    Execute TestMusicStore.


    With the JDK, for example, simply invoke the Java interpreter with TestMusicStore as an argument:

    
    D:\>java TestMusicStore
    


copyright 1996-2000 Magelang Institute dba jGuru


Main menuSection menuGive feedback on this tutorialPrevious panelNext panel
PrivacyLegalContact