For this assignment you must design a class named SimpleMusicTrack. This class m
ID: 640727 • Letter: F
Question
For this assignment you must design a class named SimpleMusicTrack. This class must implement the PlayListTrackinterface given below. You must download this file and import it into your source code folder before you can start to implement your own SimpleMusicTrack class.
It is up to you how to represent the member variables of your SimpleMusicTrack class, but it must implement all of the methods given in the MusicTrack interface. Note in particular that it must implement the getNextTrack(Scanner in) method that reads a single entry from a Scanner object (used with the input datafile).
In addition, your SimpleMusicTrack class must implement the following methods not provided in the interface, but are inherited from the Object class:
Explanation / Answer
SimpleMusicTrack.java
import java.util.Scanner;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
public class SimpleMusicTrack implements MusicTrack{
private String name;
private String artist;
private String albumName;
public SimpleMusicTrack(){}
//Convenience constructor for unit testing
public SimpleMusicTrack(String name, String artist, String album){
this.name=name;
this.artist=artist;
this.albumName=album;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name=name;
}
public String getArtist() {
return this.artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getAlbum() {
return this.albumName;
}
public void setAlbum(String album) {
this.albumName=album;
}
public boolean getNextTrack(Scanner infile) {
if(infile==null)
return false;
while(infile.hasNext()){
this.setName(infile.nextLine());
this.setArtist(infile.nextLine());
this.setAlbum(infile.nextLine());
return true;
}
return false;
}
@Override
public boolean equals(Object obj){
if(obj instanceof SimpleMusicTrack){
return EqualsBuilder.reflectionEquals(this, obj);
}
return false;
}
@Override
public String toString(){
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
MusicTrack.java
import java.util.Scanner;
public interface MusicTrack {
String getName();
void setName(String name);
String getArtist();
void setArtist(String artist);
String getAlbum();
void setAlbum(String album);
boolean getNextTrack(Scanner infile);
}
PlayList.java
public interface PlayList {
MusicTrack getNextTrack();
// Removes track from PlayList and returns it to the caller
// Returns null if the PlayList is empty
MusicTrack peekAtNextTrack();
// Returns next entry to the caller, but leaves it in the list
void addTrack(MusicTrack track);
// Adds this track to the playlist in the appropriate order
boolean isEmpty();
// Returns true if the playlist is empty
}
Project03.java
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.