In: Computer Science
Create a class, called Song. Song will have the following fields: artist (a string) title (a string) duration (an integer, recorded in seconds) collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration. Those fields should also be private. The collectionName can be public, and should be a single, shared value for all instances of Song. The constructor will take values for artist, title, and duration as arguments.
public class Song {
private String artist;
private String title;
private int duration;
public static String collectionName;
public Song(){
this.artist="";
this.title="";
this.duration=0;
}
public Song(String artist,String title,int
duration){
this.artist=artist;
this.title=title;
this.duration=duration;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
}