+1 (315) 557-6473 

Create A Program to Sort Song Data in Java Assignment Solution.


Instructions

Objective
Write a program to sort song data in java language.

Requirements and Specifications

For this project, you will be searching and sorting data related to bridges.data_src_dependent.Song objects. The Song data will be obtained from an online database and accessed via the BRIDGES API - https://bridgesdata.herokuapp.com/api/datasets/song (Links to an external site.). Here are the public methods of the bridges.data_src_dependent.Song class:
  Song (Links to an external site.) ()
  Song (Links to an external site.) (String artist, String song (Links to an external site.), String album (Links to an external site.), String lyrics (Links to an external site.), String release_date (Links to an external site.))
String
         getArtist (Links to an external site.) ()
void
         setArtist (Links to an external site.) (String artist)
String
         getSongTitle (Links to an external site.) ()
void
         setSongTitle (Links to an external site.) (String song (Links to an external site.))
String
         getAlbumTitle (Links to an external site.) ()
void
         setAlbumTitle (Links to an external site.) (String album (Links to an external site.))
String
         getLyrics (Links to an external site.)()
void
         setLyrics (Links to an external site.) (String lyrics (Links to an external site.))
String
         getReleaseDate (Links to an external site.) ()
void
         setReleaseDate (Links to an external site.) (String release_date (Links to an external site.))
You will store the bridges.data_src_dependent.Song objects in a class that you write called SongList that will provide the following functionality:
  • Read song data from the BRIDGES API.
  • Create a custom linked list of SLelement objects (http://bridgesuncc.github.io/doc/java-api/current/html/classbridges(Links to an external site.)) and populate the linked list with Song objects created from the dataset.
  •  To simplify the implementation of the linked list, you are required to implement this interface List.java Download List.java
  •  The class heading for the SongList class must be
  • public class SongList implements cmsc256.List

  •  Provide an additional method that returns a formatted list of all the songs by an artist (name given as a String parameter) to the method that appear on the linked list, grouped by album title (in alphabetical order) and by song title (in alphabetical order). The name of the method must be:
  •  public String getSongsByArtist(String artist)

  • The returned String is to be formatted with each song on a separate line with the song title, artist and album labeled as shown here:
  • Title: Harder, Better, Faster, Stronger Artist: Daft Punk Album: Discovery

  •  If no songs by the given artist are on the playlist, an appropriate message is to be displayed. Such as, “There are no songs by Tai Verdes in this playlist.”
It is expected that your program will be well documented and must contain a comment block at the beginning that includes the following information in an easy-to-read format: the file name, your name, the project number, the course identifier (CMSC 256), and the current semester, and a brief description of the file’s purpose.
Implement your file inside of a cmsc256 package. Submit the Java source code file to the Project 3 link in Gradescope.
Source Code
package cmsc256;
import bridges.data_src_dependent.Song;
/**
 * File: SongList.java
 * Name:
 * Project Number:
 * Course: CMSC 256
 * Semester:
 *
 * File implements interface List.java for storing Song objects
 */
public class SongList implements List {
    /**
     * Maximum capacity of list
     */
    private static final int CAPACITY = 300;
    /**
     * Helper class, implementing linked list node
     */
    private static class SongNode {
        Song song;
        SongNode prev;
        SongNode next;
        SongNode(Song song) {
            this.song = song;
            prev = null;
            next = null;
        }
    }
    /**
     * Linked list head node
     */
    private SongNode head;
    /**
     * Linked list tail node
     */
    private SongNode tail;
    /**
     * Reference to current node
     */
    private SongNode current;
    /**
     * Index of current node
     */
    private int currentIndex;
    /**
     * Number of elements in list
     */
    private int size;
    /**
     * No args constructor. Creates empty list
     */
    public SongList() {
        clear();
        moveToStart();
    }
    /**
     * Remove all contents from the list, so it is once again empty
     */
    @Override
    public void clear() {
        head = null;
        tail = null;
        current = null;
        currentIndex = -1;
        size = 0;
    }
    /**
     * Insert "it" at the current location
     * The client must ensure that the list's capacity is not exceeded
     * @param it element to add
     * @return true if list capacity is not exceeded
     */
    @Override
    public boolean insert(Song it) {
        if (size >= CAPACITY) {
            return false;
        }
        SongNode newNode = new SongNode(it);
        if (size == 0) {
            head = newNode;
            tail = newNode;
            current = head;
            currentIndex = 0;
        } else {
            if (current == head) {
                newNode.next = newNode;
                head.prev = newNode;
                head = newNode;
                current = head;
            } else {
                SongNode prevNode = current.prev;
                current.prev = newNode;
                newNode.next = current;
                prevNode.next = newNode;
                newNode.prev = prevNode;
                current = newNode;
            }
            size++;
        }
        return true;
    }
    /**
     * Append "it" at the end of the list
     * The client must ensure that the list's capacity is not exceeded
     * @param it element to add
     * @return true if list capacity is not exceeded
     */
    @Override
    public boolean append(Song it) {
        if (size >= CAPACITY) {
            return false;
        }
        SongNode node = new SongNode(it);
        if (tail == null) {
            head = node;
            tail = node;
            size = 1;
        } else {
            tail.next = node;
            node.prev = tail;
            tail = node;
            size++;
        }
        return true;
    }
    /**
     * Remove and return the current element
     * @return removed ex-current element
     */
    @Override
    public Song remove() {
        if (current == null) {
            return null;
        }
        Song result = current.song;
        if (size == 1) {
            head = null;
            tail = null;
            current = null;
            currentIndex = -1;
            size = 0;
        } else {
            if (current == head) {
                head = head.next;
                head.prev = null;
                current = head;
                currentIndex = 0;
            } else if (current == tail) {
                tail = tail.prev;
                tail.next = null;
                current = tail;
                currentIndex--;
            } else {
                SongNode prevNode = current.prev;
                SongNode nextNode = current.next;
                prevNode.next = nextNode;
                nextNode.prev = prevNode;
                current = prevNode;
                currentIndex--;
            }
            size--;
        }
        return result;
    }
    /**
     * Set the current position to the start of the list
     */
    @Override
    public void moveToStart() {
        current = head;
        if (current == null) {
            currentIndex = -1;
        }
        else {
            currentIndex = 0;
        }
    }
    /**
     * Set the current position to the end of the list
     */
    @Override
    public void moveToEnd() {
        current = tail;
        if (current == null) {
            currentIndex = -1;
        }
        else {
            currentIndex = size-1;
        }
    }
    /**
     * Move the current position one step left, no change if already at beginning
     */
    @Override
    public void prev() {
        if (current.prev != null) {
            current = current.prev;
        }
    }
    /**
     * Move the current position one step right, no change if already at end
     */
    @Override
    public void next() {
        if (current.next != null) {
            current = current.next;
        }
    }
    /**
     * Return the number of elements in the list
     * @return number of elements in list
     */
    @Override
    public int length() {
        return size;
    }
    /**
     * Return the position of the current element
     * @return index of current element
     */
    @Override
    public int currPos() {
        return currentIndex;
    }
    /**
     * Set the current position to "pos"
     * @param pos position to set current element to
     * @return true, if pos is valid
     */
    @Override
    public boolean moveToPos(int pos) {
        if (pos < 0 || pos >= size) {
            return false;
        }
        SongNode node = head;
        int counter = 0;
        while (counter < pos) {
            counter++;
            node = node.next;
        }
        currentIndex = pos;
        current = node;
        return true;
    }
    /**
     * Return true if current position is at end of the list
     * @return true if current position is at end of the list
     */
    @Override
    public boolean isAtEnd() {
        return current == tail;
    }
    /**
     * Return the current element
     * @return the current element
     */
    @Override
    public Song getValue() {
        if (current == null) {
            return null;
        }
        return current.song;
    }
    /**
     * Method that returns a formatted list of all the songs by an artist (name given as a String parameter)
     * to the method that appear on the linked list, grouped by album title (in alphabetical order)
     * and by song title (in alphabetical order).
     * @param artist to search songs for
     * @return string, containing string representation of all artist's songs, separated by new line character
     */
    public String getSongsByArtist(String artist) {
        if (length() == 0) {
            return "";
        }
        StringBuilder builder = new StringBuilder();
        boolean first = true;
        moveToStart();
        while(!isAtEnd()) {
            Song song = getValue();
            if (song.getArtist().equals(artist)) {
                if (!first) {
                    builder.append(System.lineSeparator());
                }
                else {
                    first = false;
                }
                builder.append("Title: ").append(song.getSongTitle())
                        .append(" Artist: ").append(song.getArtist())
                        .append(" Album: ").append(song.getAlbum());
            }
            next();
        }
        Song song = getValue();
        if (song.getArtist().equals(artist)) {
            if (!first) {
                builder.append(System.lineSeparator());
            }
            else {
                first = false;
            }
            builder.append("Title: ").append(song.getSongTitle())
                    .append(" Artist: ").append(song.getArtist())
                    .append(" Album: ").append(song.getAlbum());
        }
        return builder.toString();
    }