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
  


9. MusicStore: String Concatenation: Help page 27 of 31




  • Task 1

    Modify the method displayHoursOfOperation() so that it properly reports opening and closing times, that is, consistent with the times stored in the respective instance variables.


    The modification is quite simple. Simply break up the display string into smaller components and splice in the current int instance variables as part of the string concatenation. (The int values will be converted automatically during the concatenation.)

  • Task 2

    Add a toString() method to MusicStore that concatenates together pertinent information for the current instance and returns the resulting String.


    Recall from the course notes that toString() must return a String (otherwise, there would be no point in doing this) and it must have the public modifier:

    
      public String toString() {
        ...
      }
    
  • Task 3

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


    Simply provide an instance of MusicStore as an argument to System.out.println().

  • Task 4

    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 5

    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