Question: How do i do this part of the assignment? Did i create the setters correctly? import java.applet.AudioClip; import java.applet.Applet; import java.io.File; import java.net.URL; /** *

How do i do this part of the assignment? Did i create the setters correctly?

How do i do this part of the assignment? Did i create

import java.applet.AudioClip;

import java.applet.Applet;

import java.io.File;

import java.net.URL;

/**

* The Song class represents a song. Each song

* has a title, artist, play time, and file path.

*

* Here is an example of how a song can be created.

*

 

* Song song = new Song("Amsterdam", "Paul Oakenfold", 318, "sounds/Amsterdam.mp3");

*

*

* Here is an example of how a song can be used.

*

 

* System.out.println("Artist: " + song.getArtist());

* System.out.println(song);

*

*

* @author CS121 Instructors

*/

public class Song

{

// Used to play the song.

private AudioClip clip;

private String title;

private String artist;

private int playTime; // in seconds

private String filePath;

private int playCount;

/**

* Constructor: Builds a song using the given parameters.

* @param title song's title

* @param artist song's artist

* @param playTime song's length in seconds

* @param filePath song file to load

*/

public Song(String title, String artist, int playTime, String filePath)

{

this.title = title;

this.artist = artist;

this.playTime = playTime;

this.filePath = filePath;

this.playCount = 0;

String fullPath = new File(filePath).getAbsolutePath();

try {

this.clip = Applet.newAudioClip(new URL("file:" + fullPath));

} catch(Exception e) {

System.out.println("Error loading sound clip for " + fullPath);

System.out.println(e.getMessage());

}

}

/**

* Returns the title of this Song.

* @return the title

*/

public String getTitle()

{

return title;

}

/**

* Returns the artist of this Song.

* @return the artist

*/

public String getArtist()

{

return artist;

}

/**

* Returns the play time of this Song in seconds.

* @return the playTime

*/

public int getPlayTime()

{

return playTime;

}

/**

* Returns the file path of this Song.

* @return the filePath

*/

public String getFilePath()

{

return filePath;

}

/**

* Returns the number of times this song has been played.

* @return the count

*/

public int getPlayCount()

{

return playCount;

}

/**

* Plays this song asynchronously.

*/

public void play()

{

if(clip != null) {

clip.play();

playCount++;

}

}

/**

* Stops this song from playing.

*/

public void stop()

{

if(clip != null) {

clip.stop();

}

}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString()

{

return String.format("%-20s %-20s %-25s %10d",title, artist, filePath, playTime);

}

public String setArtist( String artist){

this.artist = artist;

return artist;

}

public String setTitle( String title){

this.title = title;

return title;

}

public String setFilePath( String filePath){

this.filePath = filePath;

return filePath;

}

public int setPlayTime(int playTime){

this.playTime = playTime;

return playTime;

}

4.1 Task 1: Add Setters to Song.java Your Song class already has getter (e.g. accessor) methods that were included in project 2. You need to modify the Song class to include setter methods. Write setter (1.e., mutator) methods for the tollowing instance variables: Write setter(i.e., mutator) methods for the following instance variables: . title (String type) artist (String type) playtime (int type) filepath(String type)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!