Write a Java class called Song to represent a song in a music collection. The da
ID: 3588108 • Letter: W
Question
Write a Java class called Song to represent a song in a music collection. The data members of the Song class are String objects representing the song title, artist’s name, and the album where the song can be found. These instance variables for the class are to have private access modifiers, so you will need to write the appropriate methods to allow a client class to access and modify the data values. In accordance with good programming practice, you are to override the equals and toString methods inherited from Object. In addition, this class is going to be used in a future project collection that is to be sorted, so you’ll need to implement the Comparable interface.
A second class is to be written called SongReader that contains a main method that reads in a file name via the command line. The file is a listing of the songs that have been formatted using angle-bracketed tags.
Each line is either a tag (opening or closing) or data. Tags are matched pairs of single words surrounded in angle brackets. Opening tags begin with an angle bracket (<) and closing tags begin with an angle bracket and forward slash (</). The tags can appear in any order, but they must be properly nested inside song tags. Any incorrectly formatted song items should be ignored by the SongReader class. Data that is not specifically enclosed in title, artist, or album tags is to be ignored. In the sample input file, playlist.data, the first five song items are valid but the last one is invalid and should be rejected by the SongReader program.
The SongReader class will open and read the input file to create Song objects by parsing the file data. You are required to use an implementation of the given StackInterface<E> interface in your project for matching opening and closing tags. You may not use any external parsing libraries. After reading the input, the SongReader class will display a list of the Song objects.
Explanation / Answer
public class SongDriver { public static void main(String[] args) { Playlist Playlist(); Song song1 = new Song("Hotline Bling", "Drake", "Hotline Bing - Single", 267000); Song song2 = new Song("What Do You Mean?", "Justin Bieber", "What Do You Mean? - Single", 207000); Song song3 = new Song("Watch Me", "Silento", "Watch Me (Whip / Nae Nae) - Single", 185000); Song song4 = new Song("679", "Fetty Wap ft. Remy Boyz", "Fetty Wap", 185000); Song song5 = new Song("Can't Feel My Face", "The Weeknd", "Beauty Behind the Madness", 213000); Song song6 = new Song("Good for You", "Selena Gomez ft. A$AP Rocky", "Good for You - Single", 221000); Song song7 = new Song("If You", "Big Bang", "MADE", 264000); one.add(song1); one.add(song2); one.add(song3); one.add(song4); one.add(song5); one.add(song6); one.add(song7); one.print(); one.remove("679"); one.remove("Watch Me"); one.print(); one.clear(); } public static long HOURS = 60 * 60 * 1000; public static long MINS = 60 * 1000; public static long SECS = 1000; public static class Playlist { private Song[] songs; private int count; private String playlistName; public Playlist() { songs = new Song[12]; count = 0; } public String getPlaylistName() { return playlistName; } public void setPlayListName() { this.playlistName = playlistName; } public void add(Song a) { if (count == songs.length) { System.out.println("ERROR: Collection is full. Songs were not added to the Playlist."); } songs[count] = a; count++; } public Song get(int i) { if (count > i) { return songs[i]; } else { return null; } } public Song remove(String name) { boolean found = false; int indexToRemove = 0; while (indexToRemoveRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.