SlideShare a Scribd company logo
I need help writing the methods for the song and playList class in Java. I already have the
interface and the getters and setter. Can someone help with the methods?
Song Class
public class Song
private String artist // the artist performing the song
private String title // the title of the song
private int minutes // number of min in length
private int seconds // number of seconds of length of the song (always less than 60)
// Add Getters / Setters for all fields
// Three constructors (remember to initialize ALL fields in each of the constructors - regardless
of the number of parameters!)
public Song(String artist, String title)
public Song(String artist, String title, int minutes, int seconds)
public Song(Song s)
public boolean equals(Object o) // a song is equal if all four fields are equal
public String toString() { // Use this code for toString EXACTLY
return "{Song: title = " + title + " artist = " + artist + "}";
}
public void play() { // Use this code for play EXACTLY
System.out.printf("Playing Song: artist = %-20s title = %s ", artist, title);
}
Make the Song class implement the interface Comparable, and make the ordering criteria as
follows: Songs will be ordered by artist in ascending order. If the artists are the same, then by
title in ascending order. If both artist and title are the same, then any order is acceptable.
Don’t forget to include any methods needed to implement the Playable interface.
PlayList Class
public class PlayList
Methods that modify the list should return a boolean return true if they successfully change the
list, otherwise they return false. Note that a PlayList can contain other PlayLists!
Methods that return a Playable element return null if they fail to find the song in question.
private String name // contains the name of the playlist
private ArrayList playableList // ArrayList of Playable elements that make up the play list
// Add Getters / Setters for name and songList
// Add a toString() method that returns the name of the playlist followed by its contents (by
calling toString() on each item it contains). You should only have one name/title per line
// Two constructors (remember to initialize ALL fields in each of the constructors - regardless of
the number of parameters!)
public PlayList() // empty play list named "Untitled"
public PlayList(String newName) // empty play list
public boolean loadSongs(String fileName) // loads songs from file, more on this below
public boolean clear() // removes all playable elements in the play list
public boolean addSong(Song s) // adds Song s to the end of the play list
public Playable removePlayable(int index) // removes Playable element at index from the list and
returns it
public Playable removePlayable(Playable p) // removes every occurrence of Playable p from the
list and returns p
public Playable getPlayable(int index) // returns the Playable element at the appropriate index
public boolean addPlayList(PlayList pl) //adds the PlayList that is being passed to the end of the
playableList and returns true unless the playableList already contains a playlist with the same
name, in this case do not add the playlist and return false. Playlists are uniquely identified by
name, so your program should not allow there to be two playlists with the same name.
public void play() // plays the play list by calling play() on each item in the play list in order
public int size() // returns the number of songs in the play list and all songs contained in any of
the nested play lists. For example if p1 is a playlist that contains songs s1, s2 and s3 as well as
play list p2. Also, suppose that p2 contains songs s4, s5, s6, and s7, then if I called size on p1 it
should return 7.
Write a method in PlayList called sortByName(). This method will sort the Playable items by the
value returned by getName() in ascending order.
You must use a comparator object with Collections.sort() to achieve this. The interface to
implement is Comparator.
Also add a method sortByTime() in PlayList that sorts by the Song or PlayList's total time in
seconds, in ascending order (shortest first). It also must use a comparator object to achieve this.
That object will use one of the methods in the Playable interface to get the time for each object.
Solution
Song class
public class Song implements Comparable {
private String artist; // the artist performing the song
private String title; // the title of the song
private int minutes; // number of min in length
private int seconds; // number of seconds of length of the song (always less than 60)
public Song(String artist, String title)
{
this.artist=artist;
this.title=title;
}
public Song(String artist, String title, int minutes, int seconds)
{
this.artist=artist;
this.title=title;
this.minutes=minutes;
this.seconds=seconds;
}
public Song(Song s)
{
this(s.artist, s.title, s.minutes, s.seconds);
}
public boolean equals(Object o) // a song is equal if all four fields are equal
{
Song s=(Song)o;
if(this.artist.equals(s.artist)&&this.title.equals(s.title)&&this.minutes==s.minutes&&this.seconds
==s.seconds)
return true;
return false;
}
public String toString() { // Use this code for toString EXACTLY
return "{Song: title = " + title + " artist = " + artist + "}";
}
public void play() { // Use this code for play EXACTLY
System.out.printf("Playing Song: artist = %-20s title = %s ", artist, title);
}
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 getMinutes() {
return minutes;
}
public void setMinutes(int minutes) {
this.minutes = minutes;
}
public int getSeconds() {
return seconds;
}
public void setSeconds(int seconds) {
this.seconds = seconds;
}
@Override
public int compareTo(Song arg0) {
int a=artist.compareTo(arg0.artist);
if(a==0)
{
a=title.compareTo(arg0.title);
}
return a;
}
}
PlayList class
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
public class PlayList {
private String name; // contains the name of the playlist
private ArrayList playableList; // ArrayList of Playable elements that make up the play list
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ArrayList getPlayableList() {
return playableList;
}
public void setPlayableList(ArrayList playableList) {
this.playableList = playableList;
}
public PlayList()
{
name="";
playableList=new ArrayList();
}
public PlayList(String newName)
{
name=newName;
playableList=new ArrayList();
}
public boolean loadSongs(String fileName) throws FileNotFoundException
{
FileReader fr = new FileReader(fileName);
Scanner sc = new Scanner(fr);
while(sc.hasNextLine())
{
String data = sc.nextLine();
String[] value = data.split(",");
Song s = new Song(value[0], value[1],
Integer.valueOf(value[2]),Integer.valueOf(value[3]));
addSong(s);
}
return true;
}
public boolean clear() // removes all playable elements in the play list
{
playableList.clear();
if(playableList.isEmpty())
return true;
return false;
}
public boolean addSong(Song s) // adds Song s to the end of the play list
{
playableList.add(s);
return false;
}
public Song removePlayable(int index) // removes Playable element at index from the list and
returns it{
{
Song s=(Song) playableList.remove(index);
return s;
}
public Song removePlayable(Song p) // removes every occurrence of Playable p from the list
and returns p
{
playableList.remove(p);
return p;
}
public Song getPlayable(int index) // returns the Playable element at the appropriate index
{
Song s=playableList.get(index);
return s;
}
public boolean addPlayList(PlayList pl) //adds the PlayList that is being passed to the end of
the playableList and returns true unless the playableList already contains a playlist with the same
name, in this case do not add the playlist and return false. Playlists are uniquely identified by
name, so your program should not allow there to be two playlists with the same name.
{
playableList.addAll(pl.getPlayableList());
return false;
}
public void play() // plays the play list by calling play() on each item in the play list in order
{
Iterator< Song> ir=playableList.iterator();
while(ir.hasNext())
{
ir.next().play();
}
}
public int size() // returns the number of songs in the play list and all songs contained in any of
the nested play lists. For example if p1 is a playlist that contains songs s1, s2 and s3 as well as
play list p2. Also, suppose that p2 contains songs s4, s5, s6, and s7, then if I called size on p1 it
should return 7.
{
playableList.size();
return 0;
}
void sortByTime()
{
Collections.sort(playableList, new SortByTime());
}
void sortByArtistName()
{
Collections.sort(playableList, new Sortbyname());
}
@Override
public String toString() {
return "PlayList [name=" + name + ", playableList=" + playableList + "]";
}
}
SortByName class
import java.util.Comparator;
/**
* implement comparator to sort volume by name
*/
public class Sortbyname implements Comparator {
@Override
public int compare(Song o1, Song o2) {
return o1.getArtist().compareTo(o2.getArtist());
}
}
SortByTime class
import java.util.Comparator;
public class SortByTime implements Comparator {
@Override
public int compare(Song arg0, Song arg1) {
if(arg0.getMinutes()>arg1.getMinutes())
return 1;
else if(arg0.getMinutes()arg1.getSeconds())
return 1;
else if(arg0.getSeconds()

More Related Content

Similar to I need help writing the methods for the song and playList class in J.pdf

8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
ARCHANASTOREKOTA
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
apleathers
 
It's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdfIt's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdf
aanyajoshi90
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
ANANDSALESINDIA105
 
I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdf
mail931892
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
fazanmobiles
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf
spshotham
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf
sastaindin
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdf
illyasraja7
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdf
arorasales234
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
mukulsingh0025
 
In C++ please I need output please You will be building a .pdf
In C++ please I need output please   You will be building a .pdfIn C++ please I need output please   You will be building a .pdf
In C++ please I need output please You will be building a .pdf
sunilverma8487
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
shreeaadithyaacellso
 
819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf
meenaaarika
 
The provided codetrack_file_handling.rb class Track att.pdf
The provided codetrack_file_handling.rb class Track    att.pdfThe provided codetrack_file_handling.rb class Track    att.pdf
The provided codetrack_file_handling.rb class Track att.pdf
fashination
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
shreeaadithyaacellso
 
Testing Jboss Seam Bottom Up
Testing Jboss Seam Bottom UpTesting Jboss Seam Bottom Up
Testing Jboss Seam Bottom Up
Dan Hinojosa
 
Swift Thinking
Swift ThinkingSwift Thinking
Swift Thinking
Natasha Murashev
 
816 LAB Playlist output linked list C++ Given main .pdf
816 LAB Playlist output linked list C++ Given main .pdf816 LAB Playlist output linked list C++ Given main .pdf
816 LAB Playlist output linked list C++ Given main .pdf
aarokyaaqua
 
The Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docxThe Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docx
AustinIKkNorthy
 

Similar to I need help writing the methods for the song and playList class in J.pdf (20)

8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
8.8 Program Playlist (Java)You will be building a linked list. Ma.pdf
 
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdfHi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
Hi,Please find the Ansswer below.PLAYLIST.h#include iostrea.pdf
 
It's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdfIt's not working what am I doing wrong- Given main()- complete the Son.pdf
It's not working what am I doing wrong- Given main()- complete the Son.pdf
 
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdfHere is the code.compile  g++ Playlist.cpp main.cppPlaylist.h.pdf
Here is the code.compile g++ Playlist.cpp main.cppPlaylist.h.pdf
 
I need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdfI need help writing test Codepackage org.example;import j.pdf
I need help writing test Codepackage org.example;import j.pdf
 
Many of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdfMany of us have large digital music collections that are not always .pdf
Many of us have large digital music collections that are not always .pdf
 
1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf1817 LAB Playlist output linked list Given main compl.pdf
1817 LAB Playlist output linked list Given main compl.pdf
 
816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf816 LAB Playlist output linked list Hey I have most of.pdf
816 LAB Playlist output linked list Hey I have most of.pdf
 
Given main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdfGiven main(), complete the SongNode class to include the printSong.pdf
Given main(), complete the SongNode class to include the printSong.pdf
 
You are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdfYou are required to implement all the classes as specified by UML di.pdf
You are required to implement all the classes as specified by UML di.pdf
 
maincpp include ltiostreamgt include ltstringgt.pdf
maincpp  include ltiostreamgt include ltstringgt.pdfmaincpp  include ltiostreamgt include ltstringgt.pdf
maincpp include ltiostreamgt include ltstringgt.pdf
 
In C++ please I need output please You will be building a .pdf
In C++ please I need output please   You will be building a .pdfIn C++ please I need output please   You will be building a .pdf
In C++ please I need output please You will be building a .pdf
 
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdfIn C++ Plz  LAB- Playlist (output linked list) Given main()- complete.pdf
In C++ Plz LAB- Playlist (output linked list) Given main()- complete.pdf
 
819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf819 LAB Program Playlist c++ You will be building a li.pdf
819 LAB Program Playlist c++ You will be building a li.pdf
 
The provided codetrack_file_handling.rb class Track att.pdf
The provided codetrack_file_handling.rb class Track    att.pdfThe provided codetrack_file_handling.rb class Track    att.pdf
The provided codetrack_file_handling.rb class Track att.pdf
 
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdfIn C++ Plz and In What Order Do I Put It In-  LAB- Playlist (output li.pdf
In C++ Plz and In What Order Do I Put It In- LAB- Playlist (output li.pdf
 
Testing Jboss Seam Bottom Up
Testing Jboss Seam Bottom UpTesting Jboss Seam Bottom Up
Testing Jboss Seam Bottom Up
 
Swift Thinking
Swift ThinkingSwift Thinking
Swift Thinking
 
816 LAB Playlist output linked list C++ Given main .pdf
816 LAB Playlist output linked list C++ Given main .pdf816 LAB Playlist output linked list C++ Given main .pdf
816 LAB Playlist output linked list C++ Given main .pdf
 
The Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docxThe Test File- The code- #include -iostream- #include -vector- #includ.docx
The Test File- The code- #include -iostream- #include -vector- #includ.docx
 

More from arihanthtextiles

How do autopolyploidy and allopolyploidy differ Only autopolyploidy.pdf
How do autopolyploidy and allopolyploidy differ  Only autopolyploidy.pdfHow do autopolyploidy and allopolyploidy differ  Only autopolyploidy.pdf
How do autopolyploidy and allopolyploidy differ Only autopolyploidy.pdf
arihanthtextiles
 
How do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdfHow do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdf
arihanthtextiles
 
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdfExplain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
arihanthtextiles
 
Dynamic routing protocols are used toa) establish paths real ti.pdf
Dynamic routing protocols are used toa) establish paths real ti.pdfDynamic routing protocols are used toa) establish paths real ti.pdf
Dynamic routing protocols are used toa) establish paths real ti.pdf
arihanthtextiles
 
Evaluate expression without a calculator. Write answer in radians..pdf
Evaluate expression without a calculator. Write answer in radians..pdfEvaluate expression without a calculator. Write answer in radians..pdf
Evaluate expression without a calculator. Write answer in radians..pdf
arihanthtextiles
 
Epithelial tissues that are only one cell thick are called _____ Epi.pdf
Epithelial tissues that are only one cell thick are called _____  Epi.pdfEpithelial tissues that are only one cell thick are called _____  Epi.pdf
Epithelial tissues that are only one cell thick are called _____ Epi.pdf
arihanthtextiles
 
Describe in five sentences how the TLR system is used to fight HSV-1 .pdf
Describe in five sentences how the TLR system is used to fight HSV-1 .pdfDescribe in five sentences how the TLR system is used to fight HSV-1 .pdf
Describe in five sentences how the TLR system is used to fight HSV-1 .pdf
arihanthtextiles
 
Daunte is frustrated about managements recent decision to merge hi.pdf
Daunte is frustrated about managements recent decision to merge hi.pdfDaunte is frustrated about managements recent decision to merge hi.pdf
Daunte is frustrated about managements recent decision to merge hi.pdf
arihanthtextiles
 
Concern over the weather associated with El Nino has increased intere.pdf
Concern over the weather associated with El Nino has increased intere.pdfConcern over the weather associated with El Nino has increased intere.pdf
Concern over the weather associated with El Nino has increased intere.pdf
arihanthtextiles
 
Clostridium difficile is a bacteria currently making headlines. It h.pdf
Clostridium difficile is a bacteria currently making headlines. It h.pdfClostridium difficile is a bacteria currently making headlines. It h.pdf
Clostridium difficile is a bacteria currently making headlines. It h.pdf
arihanthtextiles
 
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdfYou cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
arihanthtextiles
 
You have constructed a new reporter gene to help you find novel zebr.pdf
You have constructed a new reporter gene to help you find novel zebr.pdfYou have constructed a new reporter gene to help you find novel zebr.pdf
You have constructed a new reporter gene to help you find novel zebr.pdf
arihanthtextiles
 
Write a Java program that will incorporate either a sequential searc.pdf
Write a Java program that will incorporate either a sequential searc.pdfWrite a Java program that will incorporate either a sequential searc.pdf
Write a Java program that will incorporate either a sequential searc.pdf
arihanthtextiles
 
Answer only with excel instructions.Assume that 96 of ticket hold.pdf
Answer only with excel instructions.Assume that 96 of ticket hold.pdfAnswer only with excel instructions.Assume that 96 of ticket hold.pdf
Answer only with excel instructions.Assume that 96 of ticket hold.pdf
arihanthtextiles
 
A new species of sea horse has been discovered and is being sequenced.pdf
A new species of sea horse has been discovered and is being sequenced.pdfA new species of sea horse has been discovered and is being sequenced.pdf
A new species of sea horse has been discovered and is being sequenced.pdf
arihanthtextiles
 
Which of the following is the mechanism of action for Herceptin Her.pdf
Which of the following is the mechanism of action for Herceptin  Her.pdfWhich of the following is the mechanism of action for Herceptin  Her.pdf
Which of the following is the mechanism of action for Herceptin Her.pdf
arihanthtextiles
 
Which of these statements best describes an element An element is c.pdf
Which of these statements best describes an element  An element is c.pdfWhich of these statements best describes an element  An element is c.pdf
Which of these statements best describes an element An element is c.pdf
arihanthtextiles
 
What is the general goal for descriptive statistics How is the goal.pdf
What is the general goal for descriptive statistics  How is the goal.pdfWhat is the general goal for descriptive statistics  How is the goal.pdf
What is the general goal for descriptive statistics How is the goal.pdf
arihanthtextiles
 
What effects are shown on this graph (assume that all effects where.pdf
What effects are shown on this graph (assume that all effects where.pdfWhat effects are shown on this graph (assume that all effects where.pdf
What effects are shown on this graph (assume that all effects where.pdf
arihanthtextiles
 
What are adaptive peaks How do organisms move from one adaptive pea.pdf
What are adaptive peaks How do organisms move from one adaptive pea.pdfWhat are adaptive peaks How do organisms move from one adaptive pea.pdf
What are adaptive peaks How do organisms move from one adaptive pea.pdf
arihanthtextiles
 

More from arihanthtextiles (20)

How do autopolyploidy and allopolyploidy differ Only autopolyploidy.pdf
How do autopolyploidy and allopolyploidy differ  Only autopolyploidy.pdfHow do autopolyploidy and allopolyploidy differ  Only autopolyploidy.pdf
How do autopolyploidy and allopolyploidy differ Only autopolyploidy.pdf
 
How do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdfHow do you find the order of growth for the following recurrenceT.pdf
How do you find the order of growth for the following recurrenceT.pdf
 
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdfExplain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
Explain SEAD, SAR and SPAAR routing protocols in more details.So.pdf
 
Dynamic routing protocols are used toa) establish paths real ti.pdf
Dynamic routing protocols are used toa) establish paths real ti.pdfDynamic routing protocols are used toa) establish paths real ti.pdf
Dynamic routing protocols are used toa) establish paths real ti.pdf
 
Evaluate expression without a calculator. Write answer in radians..pdf
Evaluate expression without a calculator. Write answer in radians..pdfEvaluate expression without a calculator. Write answer in radians..pdf
Evaluate expression without a calculator. Write answer in radians..pdf
 
Epithelial tissues that are only one cell thick are called _____ Epi.pdf
Epithelial tissues that are only one cell thick are called _____  Epi.pdfEpithelial tissues that are only one cell thick are called _____  Epi.pdf
Epithelial tissues that are only one cell thick are called _____ Epi.pdf
 
Describe in five sentences how the TLR system is used to fight HSV-1 .pdf
Describe in five sentences how the TLR system is used to fight HSV-1 .pdfDescribe in five sentences how the TLR system is used to fight HSV-1 .pdf
Describe in five sentences how the TLR system is used to fight HSV-1 .pdf
 
Daunte is frustrated about managements recent decision to merge hi.pdf
Daunte is frustrated about managements recent decision to merge hi.pdfDaunte is frustrated about managements recent decision to merge hi.pdf
Daunte is frustrated about managements recent decision to merge hi.pdf
 
Concern over the weather associated with El Nino has increased intere.pdf
Concern over the weather associated with El Nino has increased intere.pdfConcern over the weather associated with El Nino has increased intere.pdf
Concern over the weather associated with El Nino has increased intere.pdf
 
Clostridium difficile is a bacteria currently making headlines. It h.pdf
Clostridium difficile is a bacteria currently making headlines. It h.pdfClostridium difficile is a bacteria currently making headlines. It h.pdf
Clostridium difficile is a bacteria currently making headlines. It h.pdf
 
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdfYou cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
You cloned an EcoRI digested DNA fragment into a unique EcoRI site o.pdf
 
You have constructed a new reporter gene to help you find novel zebr.pdf
You have constructed a new reporter gene to help you find novel zebr.pdfYou have constructed a new reporter gene to help you find novel zebr.pdf
You have constructed a new reporter gene to help you find novel zebr.pdf
 
Write a Java program that will incorporate either a sequential searc.pdf
Write a Java program that will incorporate either a sequential searc.pdfWrite a Java program that will incorporate either a sequential searc.pdf
Write a Java program that will incorporate either a sequential searc.pdf
 
Answer only with excel instructions.Assume that 96 of ticket hold.pdf
Answer only with excel instructions.Assume that 96 of ticket hold.pdfAnswer only with excel instructions.Assume that 96 of ticket hold.pdf
Answer only with excel instructions.Assume that 96 of ticket hold.pdf
 
A new species of sea horse has been discovered and is being sequenced.pdf
A new species of sea horse has been discovered and is being sequenced.pdfA new species of sea horse has been discovered and is being sequenced.pdf
A new species of sea horse has been discovered and is being sequenced.pdf
 
Which of the following is the mechanism of action for Herceptin Her.pdf
Which of the following is the mechanism of action for Herceptin  Her.pdfWhich of the following is the mechanism of action for Herceptin  Her.pdf
Which of the following is the mechanism of action for Herceptin Her.pdf
 
Which of these statements best describes an element An element is c.pdf
Which of these statements best describes an element  An element is c.pdfWhich of these statements best describes an element  An element is c.pdf
Which of these statements best describes an element An element is c.pdf
 
What is the general goal for descriptive statistics How is the goal.pdf
What is the general goal for descriptive statistics  How is the goal.pdfWhat is the general goal for descriptive statistics  How is the goal.pdf
What is the general goal for descriptive statistics How is the goal.pdf
 
What effects are shown on this graph (assume that all effects where.pdf
What effects are shown on this graph (assume that all effects where.pdfWhat effects are shown on this graph (assume that all effects where.pdf
What effects are shown on this graph (assume that all effects where.pdf
 
What are adaptive peaks How do organisms move from one adaptive pea.pdf
What are adaptive peaks How do organisms move from one adaptive pea.pdfWhat are adaptive peaks How do organisms move from one adaptive pea.pdf
What are adaptive peaks How do organisms move from one adaptive pea.pdf
 

Recently uploaded

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 

I need help writing the methods for the song and playList class in J.pdf

  • 1. I need help writing the methods for the song and playList class in Java. I already have the interface and the getters and setter. Can someone help with the methods? Song Class public class Song private String artist // the artist performing the song private String title // the title of the song private int minutes // number of min in length private int seconds // number of seconds of length of the song (always less than 60) // Add Getters / Setters for all fields // Three constructors (remember to initialize ALL fields in each of the constructors - regardless of the number of parameters!) public Song(String artist, String title) public Song(String artist, String title, int minutes, int seconds) public Song(Song s) public boolean equals(Object o) // a song is equal if all four fields are equal public String toString() { // Use this code for toString EXACTLY return "{Song: title = " + title + " artist = " + artist + "}"; } public void play() { // Use this code for play EXACTLY System.out.printf("Playing Song: artist = %-20s title = %s ", artist, title); } Make the Song class implement the interface Comparable, and make the ordering criteria as follows: Songs will be ordered by artist in ascending order. If the artists are the same, then by title in ascending order. If both artist and title are the same, then any order is acceptable. Don’t forget to include any methods needed to implement the Playable interface. PlayList Class public class PlayList Methods that modify the list should return a boolean return true if they successfully change the list, otherwise they return false. Note that a PlayList can contain other PlayLists! Methods that return a Playable element return null if they fail to find the song in question. private String name // contains the name of the playlist private ArrayList playableList // ArrayList of Playable elements that make up the play list // Add Getters / Setters for name and songList // Add a toString() method that returns the name of the playlist followed by its contents (by calling toString() on each item it contains). You should only have one name/title per line
  • 2. // Two constructors (remember to initialize ALL fields in each of the constructors - regardless of the number of parameters!) public PlayList() // empty play list named "Untitled" public PlayList(String newName) // empty play list public boolean loadSongs(String fileName) // loads songs from file, more on this below public boolean clear() // removes all playable elements in the play list public boolean addSong(Song s) // adds Song s to the end of the play list public Playable removePlayable(int index) // removes Playable element at index from the list and returns it public Playable removePlayable(Playable p) // removes every occurrence of Playable p from the list and returns p public Playable getPlayable(int index) // returns the Playable element at the appropriate index public boolean addPlayList(PlayList pl) //adds the PlayList that is being passed to the end of the playableList and returns true unless the playableList already contains a playlist with the same name, in this case do not add the playlist and return false. Playlists are uniquely identified by name, so your program should not allow there to be two playlists with the same name. public void play() // plays the play list by calling play() on each item in the play list in order public int size() // returns the number of songs in the play list and all songs contained in any of the nested play lists. For example if p1 is a playlist that contains songs s1, s2 and s3 as well as play list p2. Also, suppose that p2 contains songs s4, s5, s6, and s7, then if I called size on p1 it should return 7. Write a method in PlayList called sortByName(). This method will sort the Playable items by the value returned by getName() in ascending order. You must use a comparator object with Collections.sort() to achieve this. The interface to implement is Comparator. Also add a method sortByTime() in PlayList that sorts by the Song or PlayList's total time in seconds, in ascending order (shortest first). It also must use a comparator object to achieve this. That object will use one of the methods in the Playable interface to get the time for each object. Solution Song class public class Song implements Comparable { private String artist; // the artist performing the song private String title; // the title of the song
  • 3. private int minutes; // number of min in length private int seconds; // number of seconds of length of the song (always less than 60) public Song(String artist, String title) { this.artist=artist; this.title=title; } public Song(String artist, String title, int minutes, int seconds) { this.artist=artist; this.title=title; this.minutes=minutes; this.seconds=seconds; } public Song(Song s) { this(s.artist, s.title, s.minutes, s.seconds); } public boolean equals(Object o) // a song is equal if all four fields are equal { Song s=(Song)o; if(this.artist.equals(s.artist)&&this.title.equals(s.title)&&this.minutes==s.minutes&&this.seconds ==s.seconds) return true; return false; } public String toString() { // Use this code for toString EXACTLY return "{Song: title = " + title + " artist = " + artist + "}"; } public void play() { // Use this code for play EXACTLY System.out.printf("Playing Song: artist = %-20s title = %s ", artist, title); } public String getArtist() {
  • 4. 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 getMinutes() { return minutes; } public void setMinutes(int minutes) { this.minutes = minutes; } public int getSeconds() { return seconds; } public void setSeconds(int seconds) { this.seconds = seconds; } @Override public int compareTo(Song arg0) { int a=artist.compareTo(arg0.artist); if(a==0) { a=title.compareTo(arg0.title); } return a; } } PlayList class import java.io.FileNotFoundException; import java.io.FileReader;
  • 5. import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Scanner; public class PlayList { private String name; // contains the name of the playlist private ArrayList playableList; // ArrayList of Playable elements that make up the play list public String getName() { return name; } public void setName(String name) { this.name = name; } public ArrayList getPlayableList() { return playableList; } public void setPlayableList(ArrayList playableList) { this.playableList = playableList; } public PlayList() { name=""; playableList=new ArrayList(); } public PlayList(String newName) { name=newName; playableList=new ArrayList(); } public boolean loadSongs(String fileName) throws FileNotFoundException { FileReader fr = new FileReader(fileName); Scanner sc = new Scanner(fr); while(sc.hasNextLine()) { String data = sc.nextLine();
  • 6. String[] value = data.split(","); Song s = new Song(value[0], value[1], Integer.valueOf(value[2]),Integer.valueOf(value[3])); addSong(s); } return true; } public boolean clear() // removes all playable elements in the play list { playableList.clear(); if(playableList.isEmpty()) return true; return false; } public boolean addSong(Song s) // adds Song s to the end of the play list { playableList.add(s); return false; } public Song removePlayable(int index) // removes Playable element at index from the list and returns it{ { Song s=(Song) playableList.remove(index); return s; } public Song removePlayable(Song p) // removes every occurrence of Playable p from the list and returns p { playableList.remove(p); return p; } public Song getPlayable(int index) // returns the Playable element at the appropriate index { Song s=playableList.get(index);
  • 7. return s; } public boolean addPlayList(PlayList pl) //adds the PlayList that is being passed to the end of the playableList and returns true unless the playableList already contains a playlist with the same name, in this case do not add the playlist and return false. Playlists are uniquely identified by name, so your program should not allow there to be two playlists with the same name. { playableList.addAll(pl.getPlayableList()); return false; } public void play() // plays the play list by calling play() on each item in the play list in order { Iterator< Song> ir=playableList.iterator(); while(ir.hasNext()) { ir.next().play(); } } public int size() // returns the number of songs in the play list and all songs contained in any of the nested play lists. For example if p1 is a playlist that contains songs s1, s2 and s3 as well as play list p2. Also, suppose that p2 contains songs s4, s5, s6, and s7, then if I called size on p1 it should return 7. { playableList.size(); return 0; } void sortByTime() { Collections.sort(playableList, new SortByTime()); } void sortByArtistName() { Collections.sort(playableList, new Sortbyname()); }
  • 8. @Override public String toString() { return "PlayList [name=" + name + ", playableList=" + playableList + "]"; } } SortByName class import java.util.Comparator; /** * implement comparator to sort volume by name */ public class Sortbyname implements Comparator { @Override public int compare(Song o1, Song o2) { return o1.getArtist().compareTo(o2.getArtist()); } } SortByTime class import java.util.Comparator; public class SortByTime implements Comparator { @Override public int compare(Song arg0, Song arg1) { if(arg0.getMinutes()>arg1.getMinutes()) return 1; else if(arg0.getMinutes()arg1.getSeconds()) return 1; else if(arg0.getSeconds()