|
by
[Exercise |
API Docs |
Short Course|
Exercises]
|
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() {
...
}
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 jGuru.com. All Rights Reserved.
|
| ||||||||||||