Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

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, artists 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 youll 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

the trapeze swinger iron & wine the trapeze swinger - single

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 ( 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. error log should be in the same format as given data, returning the entirety of the bad "song'' not just where the error is occuring. tags must be exactly as shown in example and cannot overlap inside each other. extra data outside of tags in inside song tag specifically may be ignored. 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.)

It is expected that your program will be well documented and you are required to write a private helper method called printHeading in the SongReader class that outputs the following information to the console in an easy-toread format: your name, the project number, the course identifier (CMSC 256), and the current semester. You will call this method as the first statement in your main method. All files must contain a comment block at the beginning that includes the file name; all of the same information that was specified for the helper method printHeading; and a brief description of the files purpose. should be two seperate files, song.java and songReader.java

Stack Implementation :

import java.util.EmptyStackException;

public class LinkedStack implements StackInterface { private Node topNode; public LinkedStack() { topNode = null; } private class Node { private T data; private Node next; private Node(T d, Node n) { data = d; next = n; } private T getData() { return data; } private Node getNextNode() { return next; } } @Override public void push(T newEntry) { topNode = new Node(newEntry, topNode); }

@Override public T pop() { if(isEmpty()) { throw new EmptyStackException(); } T top = topNode.getData(); topNode = topNode.getNextNode(); return top; }

@Override public T peek() { if(isEmpty()) { throw new EmptyStackException(); } return topNode.getData(); }

@Override public boolean isEmpty() { return topNode == null; }

@Override public void clear() { topNode = null; }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions