Class Music Organizer
import java.util.ArrayList;
/**
*
*
* @author (Ismail)
* @version (14102018)
*/
public class Musicorganizer
{
private ArrayList<String> files;
private Musicplayer player;
//membuat sebuah music organizer
public Musicorganizer()
{
files = new ArrayList<>();
player = new Musicplayer();
}
//menambahkan file ke koleksi
public void addFile(String filename)
{
files.add(filename);
}
//memasukkan jumlah file ke koleksi
public int getNumberOfFiles()
{
return files.size();
}
//list file dari koleksi
public void listFile(int index)
{
if(index >= 0 && index < files.size()){
String filename = files.get(index);
System.out.println(filename);
}
}
//menghapus file di koleksi
public void removeFile(int index)
{
if(index >= 0 && index < files.size()){
files.remove(index);
}
}
//memainkan file musik di koleksi
public void startPlaying(int index)
{
String filename = files.get(index);
player.startPlaying(filename);
}
//menghentikan player musik
public void stopPlaying()
{
player.stopPlaying();
}
}
Class Music Player
/**
*
*
* @author (Ismail)
* @version (14102018)
*/
public class Musicplayer
{
private String music;
public Musicplayer()
{
music = null;
}
public void startPlaying(String filename)
{
music = filename;
System.out.println(music+ " Is Now Playing");
}
public void stopPlaying()
{
System.out.println("The Music Stop Playing");
}
}
Hasil Output program
1. Menambahkan lagu ke playlist
2. Mengecek list lagu
3. Memainkan dan menghentikan lagu
Tidak ada komentar:
Posting Komentar