AdSense

Monday, March 16, 2015

Design a music juke box

A music juke box will possibly need: a CD player, A set of CDs, a program to set tracks and a user.

The rule of OOD suggests that we should wrap up data with their operating functions in a single entity class, so we need to following classes"


  • JukeBox: Of course, that's what we are designing.
  • CD player: to play CDs
  • CD: well, to play
  • Playlist: a user defined playlist that allows the user to query the songs he/she wants to play
  • Song: yeah, it's music...
  • TrackSelector: that is the program to set and get the track
  • User: who is playing? The current design only allows for one user at a time. 


JukeBox:

public class JukeBox{
 private CDPlayer cdPlayer;
 private User user;
 private Set cdCollection;
 private TrackSelector ts;
 
 public JukeBox(CDPlayer cdPlayer, User user, Set cdCollection, TrackSelector ts){
 }
 public Song getCurrentTrack(){
  return ts.getCurrentSong();
 }
        public void setCurrentTrack(Song s){
  ts.setCurrentSong(s);
 }
 public void setNextTrack(Song s){
  ts.setNext(s);
 }
 public void processOneUser(User u){
  this.user = u;
 }
}


CD player:
CD player contains a playlist, the CD that it is currently playing, and the button to play a track.


public class CDPlayer{
 private Playlist p;
 private CD c;
 public Playlist getPlaylist(){
  return p;
 }
 public void setPlaylist(Playlist p){
  this.p = p;
 }
 public CD getCD(){
  return c;
 }
 public void setCD(CD c){
  this.c = c;
 }
 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){
 }
}

CD: 
Well, as you can imagine, a CD contains name, and list of songs. Of course we can also add artist, number of songs and so on, but just for simplicity, I only include the first two.


public class CDPlayer{
 private Playlist p;
 private CD c;
 public Playlist getPlaylist(){
  return p;
 }
 public void setPlaylist(Playlist p){
  this.p = p;
 }
 public CD getCD(){
  return c;
 }
 public void setCD(CD c){
  this.c = c;
 }
 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){
 }
}


Playlist:
A playlist will include, the CD that creates the play list and a queue of songs in the list.


public class Playlist{
 private CD cd;
 private Queue queue;
}


Song: 
The song, as you can imagine, may include the name of the song, lyrics the artist who create the song and so on.


public class Song{
 private String songName;
 private String lyrics;
 private String artist;
 public String getName(){
  return songName;
 }
}


TrackSelector: 
The track selector definitely allows us to select tracks, so it includes a song that is currently playing, set a song that the user wants to play next, switch the current playing song, and get the current playing song.


public class TrackSelector{
 private Song currentSong;
 private Song nextSong;
 //assume not playing any song at the beginning 
 public TrackSelector(){
  currentSong = "";
  nextSong = "";
 }
 public void setCurrent(Song s){
  currentSong = s;
 }
 public void setNext(Song s){
  nextSong = s;
 }
 public Song getCurrentSong(){
  return currentSong;
 }
}


User: 
The user will have a name (Who doesn't? ) and a unique ID.


public class User{
 private String name;
 private long ID;
 public User(String name, long id){
  this.name = name;
  ID = id;
 }
 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 User getUser(){
  return this;
 }
}

1 comment:


  1. The development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. IEEE final year projects on machine learning In case you will succeed, you have to begin building machine learning projects in the near future.

    Projects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.


    Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.

    ReplyDelete