Music Organizer
Music Organizer
import java.util.ArrayList;
/**
* Write a description of class MusicOrganizer here.
*/
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<>();
}
/**
* 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.
*/
public void StartPlaying(int index)
{
if(index >= 0 && index < files.size()) {
String filename = files.get(index);
System.out.println("Now Playing : ");
System.out.println(filename);
}
}
/**
* Remove a file from the collection.
* @param index The index of the file to be removed.
*/
public void removeFile(int index)
{
if(index >= 0 && index < files.size()) {
files.remove(index);
}
}
public void StopPlaying(){
System.out.println("==============================");
System.out.println("Music Has Stopped");
System.out.println("==============================");
}
}
Komentar
Posting Komentar