Thursday, October 1, 2015

[7.3] music juke box

1 Example
Music Jukebox
               ________
              /   O     (|)  \
              |  =====    |
              |   _  _   _   |
              |  |_| |_| |_|  |
              |   _  _   _   |
              |  |_| |_| |_|  |      
              |________ |
                |           |
JukeBox
  - CDPlayer
  - User
  - Set<CD>
 - TRackSelector
 - Song getCurrentTrack()
 - void processOneUser(User u)
CDPlayer

TRackSelector
  - Song currentSong
  - void setTrack(Song s)
  - getCurrentSong()
Playlist
  - ArrayList<song>
  - Queue<Song> 
  - Song track
  - add 
  - getNextTrackToPlay()
  - void queueUpTrack(Song s) 
User
  -  name
  - ID
  - getID, setID
  - getName. setName
  - addUser(String n, long id)
Song
  -name

2. implementation
CD album
a Collection of all CD in a matrix form
matrix[][]
CD class
  - name
  - number of songs
  - album price
  - album published year
Song class
  -song name
  - song duration
  - song price
 - song singer
 - song published year
PLAY class
 - play
 - delete
 -

*********************
class CDPlayer VS class Playlist
Let's first understand the basic system components:
=>CD player
=>CD
=>Display() (display length of song, remaining time and playlist)

Now, let's break this down further:
-playlist creation (includes add, delete, shuffle etc sub functionalities)
- CD selector
-Queueing up a song
- Get next song from playlist
-Track selector

A user can be introduced:
 -Adding
 - Deleting
-credit information


public class CD{}
public class CDPlayer
{
    private Playlist p;
    private CD c;
    
    public Playlist getPlaylist() {return p;}
    public void setPlaylist() {this.p = p;}
    
    public CD getCD(){return c;}
    public void setCD(CD c ){ this.c = c;}
    


    // 3 Constructors
    public CDPlayer(Playlist p){this.p = p;}
    public CDPlayer(CD c, Playlist p){...}
    public CDPlayer(CD c){this.c = c;}
 

    
    public void playTrack(Song s){...}
}

//*** The Machine
public class JukeBox 
{
    private CDPlayer cdPlayer;
    private User user;
    private Set cdCollection;
    private TrackSelector ts;

  

    // Constructor
    public JukeBox(CDPlayer cdPlayer, User user, Set cdCollection, TrackSelector ts){...}



    public Song getCurrentTrack() {return ts.getCurrentSong();}
    public void processOneUser(User u){this.user = u;}
}

// a collection of songs, add a song and pop up a song
public class Playlist 
{
    private Song track;
    private Queue queue;



    // Constructor
    public Playlist(Song track, Queue queue){...}



    public Song getNextTrackToPlay() {return queue.peek();}
    public void queueUpTrack(Song s){queue.add(s);}
}
public class Song
{
    private String songName;
}

public class TrackSelector
{
    private Song currentSong;
    


    // Constructor
    public TrackSelector(Song s ){currentSong = s;}



    public void setTrack(Song s ){currentSong = s; }
    public Song getCurrentSong() {return currentSong;}
}

public class User
{
    private String name;
    private long ID; 
  
    
    // Constructor
    public User(String name, long ID){...}
    public User getUser(){return this;}


    public String getName() {return name;} 
    public void setName(String name) {this.name = name;}
    
    public long getID() {return ID;}
    public void setID(long ID){ ID = ID;}


    public static User addUser(String name, long ID){...}
    

}
.3 similar Ones

No comments:

Post a Comment