Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java class called Song to represent a song in a music collection. The da

ID: 3740431 • 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 that includes the song. The 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. For example,

<song> <title> Savior </title> <artist> Rise Against </artist> <album> Appeal To Reason </album> </song>

Each line will a tag (opening or closing), data, or a combination of these elements. Tags are matched pairs of single words surrounded by angle brackets. Opening tags begin with an angle bracket (<) and closing tags begin with an angle bracket and forward slash (</) The tag pairs can appear in any order, but they must be properly nested inside song tags.

Input is read by the SongReader class. When reading the input file, data that is not specifically enclosed in song, title, artist, or album tags is to be ignored. The name of the input file will be provided as a command line argument. If the file name is missing or the file cannot be opened, the program should prompt the user to enter a new file name.

Any incorrectly formatted song data should be collected in a report and printed out in an error report to a file called ErrorLog.txt. In the example shown above the first two songs are correctly formatted, but the third one is not because the artist tag is inside of the title tag. As another example, in the sample input file, playlist.data, the first five song items are valid but the last one is invalid and should be reported as an error 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 interface in your project for matching opening and closing tags. You do not have to implement the interface, you may use one of the implementations that we have discussed in class and can be found in the Stacks content area of Blackboard. You may not use any external parsing libraries. After reading the input, the SongReader class will display a list of the valid Song objects. (Note that your code must create a collection of Song objects and iterate over the collection to display the information.)

Explanation / Answer

class Song {
private String title;
private String artist;
private String album;

public Song() {
this("","","");
}

public Song(String title, String artist, String album) {
this.title =title ;
this.artist = artist;
this.album = album;
}

public String getTitle() { return title; }
public String getArtist() { return artist; }
public String getAlbum() { return album; }
public void putTitle(String title) { this.title =title ; }
public void putArtist(String artist) { this.artist = artist; }
public void putAlbum(String album) { this.album = album; }
  
public String toString() {
return(""" + title + "" by " + artist + " from album: " +album);
}
  
public boolean equals(Song obj) {

  
if (obj == this) {
return true;
}


if (!(obj instanceof Song)) {
return false;
}

Song c = (Song) obj;
return (title.equals(c.title))&&(artist.equals(c.artist))&&(album.equals(c.album));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote