Tip of the day
News
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 tobridges.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:
- 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.”
Title: Harder, Better, Faster, Stronger Artist: Daft Punk Album: Discovery
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(); }
Related Samples
Discover our Java Assignment samples, covering fundamental to advanced topics in object-oriented programming. Explore solutions for data structures, algorithms, GUI development, and more. Each example includes clear, well-commented code and explanations to facilitate understanding and improve your Java programming skills effectively.
Java
Word Count
3961 Words
Writer Name:Chloe Wong
Total Orders:590
Satisfaction rate:
Java
Word Count
5749 Words
Writer Name:Tia Connor
Total Orders:964
Satisfaction rate:
Java
Word Count
4042 Words
Writer Name:Dr. Chloe jhones
Total Orders:750
Satisfaction rate:
Java
Word Count
6299 Words
Writer Name:Dr. Amanda C. Smallwood
Total Orders:356
Satisfaction rate:
Java
Word Count
4093 Words
Writer Name:Dr. Donald K. Grainger
Total Orders:689
Satisfaction rate:
Java
Word Count
3941 Words
Writer Name:Dr. Robert M. Sanchez
Total Orders:425
Satisfaction rate:
Java
Word Count
6086 Words
Writer Name:Prof. Liam Saunders
Total Orders:900
Satisfaction rate:
Java
Word Count
5597 Words
Writer Name:Dr. Candace J. Gentry
Total Orders:621
Satisfaction rate:
Java
Word Count
4942 Words
Writer Name:Dr. Julia Wong
Total Orders:426
Satisfaction rate:
Java
Word Count
6782 Words
Writer Name:Dr. Ophelia Whitethorn
Total Orders:759
Satisfaction rate:
Java
Word Count
5142 Words
Writer Name:Jessica Miller
Total Orders:652
Satisfaction rate:
Java
Word Count
8786 Words
Writer Name:Prof. Alexander Choice
Total Orders:900
Satisfaction rate:
Java
Word Count
6994 Words
Writer Name:Alex Thompson
Total Orders:1521
Satisfaction rate:
Java
Word Count
6718 Words
Writer Name:Chloe Wong
Total Orders:590
Satisfaction rate:
Java
Word Count
4871 Words
Writer Name:Dr. Marlowe Emberly
Total Orders:789
Satisfaction rate:
Java
Word Count
8521 Words
Writer Name:Dr. Zara Silvermist
Total Orders:654
Satisfaction rate:
Java
Word Count
3595 Words
Writer Name:Dr. Seraphina Stormcloud
Total Orders:852
Satisfaction rate:
Java
Word Count
3694 Words
Writer Name:Dr. George M. Long
Total Orders:507
Satisfaction rate:
Java
Word Count
4842 Words
Writer Name:Professor Harriet Sinclair
Total Orders:387
Satisfaction rate:
Java
Word Count
4329 Words
Writer Name:Dr. Seraphina Stormcloud
Total Orders:852
Satisfaction rate: