Nama : Edgar Andrew Hutauruk
NRP : 05111740000166
Kelas : PBO-B
MusicOrganizer
MusicPlayer
NRP : 05111740000166
Kelas : PBO-B
MusicOrganizer
import java.util.ArrayList;
/**
* Write a description of class MusicOrganizer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MusicOrganizer
{
private ArrayList<String> files;
private MusicPlayer player;
public MusicOrganizer()
{
files = new ArrayList<String>();
player = new MusicPlayer();
}
public void addFile(String filename)
{
files.add(filename);
}
public int getNumberOffFiles()
{
return files.size();
}
public void listFile(int index)
{
if(index >=0 && index <files.size())
{
String filename = files.get(index);
System.out.println(filename);
}
}
public void listAllFiles()
{
int i=0;
for(String filename : files)
{
System.out.println(i+":"+filename);
i++;
}
}
public void removeFile(int index)
{
if(index >=0 && index <files.size())
{
files.remove(index);
}
}
public void startPlaying(int index)
{
if(validIndex(index))
{
String filename = files.get(index);
player.startPlaying(filename);
}
}
public void playAndWait(int index)
{
if(validIndex(index))
{
String filename = files.get(index);
player.startPlaying(filename);
}
}
public boolean validIndex(int index)
{
boolean valid;
if(index<0)
{
System.out.println("Index cannot be negative: "+index);
valid = false;
}
else if(index>= files.size())
{
System.out.println("Index is too large: "+ index);
valid=false;
}
else
{
valid = true;
}
return valid;
}
}
MusicPlayer
/**
* Write a description of class MusicPlayer here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MusicPlayer
{
private String Music;
public MusicPlayer()
{
Music = "Lagu tidak ada";
}
public void startPlaying(String filename)
{
Music = filename;
System.out.println("Sedang memutar :"+Music);
}
}
Komentar
Posting Komentar