Java Reference
In-Depth Information
Code 4.1
The
MusicOrganizer
class
import
java.util.ArrayList;
/**
* A class to hold details of audio files.
*
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
*/
public
class
MusicOrganizer
{
// An ArrayList for storing the file names of music files.
private
ArrayList<String> files;
/**
* Create a MusicOrganizer
*/
public
MusicOrganizer()
{
files =
new
ArrayList<String>();
}
/**
* Add a file to the collection.
* @param filename The file to be added.
*/
public
void
addFile(String filename)
{
files.add(filename);
}
/**
* Return the number of files in the collection.
* @return The number of files in the collection.
*/
public
int
getNumberOfFiles()
{
return
files.size();
}
/**
* List a file from the collection.
* @param index The index of the file to be listed.
*/
Search WWH ::
Custom Search