Bad Guy Billie Eilish Old TOwn ROad Lil Nas X SOmeOne yOu lOved Lewis Capaldi CS 304 Homework Assignment 4 Due: 11:59pm, Thursday, March 18th This assignment is scored out of 59. There is a...

1 answer below »
please see attached file


Bad Guy Billie Eilish Old TOwn ROad Lil Nas X SOmeOne yOu lOved Lewis Capaldi CS 304 Homework Assignment 4 Due: 11:59pm, Thursday, March 18th This assignment is scored out of 59. There is a programming question and you will need to put all your Java programs (*.java) as well as output files for this question in the folder named LastName_FirstName_CS304_HW4. Zip this folder. Programming Questions P4. (44pts) a. Completing the SongList class In this program, you will implement a sorted circular linked list of songs. Each song has an artist and a title. A sample song list looks as follows (the only reference to the list is m_last, which points to the last node of the list): m_last You are provided with the files "Song.java" and "SongList.java". You are required complete the methods in the latter file to implement the sorted circular linked list. The list is sorted according to the title of each song in alphabetical order. You need to write these methods: add(String artist, String title) – This method takes an artist and a title and adds a Song node with these values into the list. The list must still be sorted in ascending order by song title. You do not need to handle duplicates – you can assume that we never insert the same song for more than once. remove(String artist, String title) – This method takes an artist and a title and remove a Song node that matches the artist and the title from the list. If remove is successful, return true. If no such node exists, return false. buildList(String artist) – This method takes an artist and searches in the list for all the song nodes associated with this artist. It then adds all these nodes into a new sorted circular linked list and returns it as a SongList object. Do not alter the original song list in this method. Note that you are only supposed to touch the above methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than these four methods or files other than "SongList.java". Points will be taken off if you fail to follow this rule. b. Code Testing You are provided with a test driver implemented by "TestSongList.java" (Do not make any changes to this file!) so there is no need to write your own. Once you have completed the methods, you can run the test. You should create a plain text file named "output.txt", copy and paste the output (if your code crashes or does not compile, copy and paste the error messages) to this file and save it. Grading Rubrics: Code does not compile: -10 Code compiles but crashes when executed: -5 Changes were made to things other than the required methods: -5 Has output file: 5 Methods were implemented and code passes 13 test cases: 39 (each test case worth 3 points) Sample output: Test 1: [Passed] add("Lewis Capaldi", "Someone You Loved") Expected return of isEmpty(): false Your isEmpty() returns: false Test 2: [Passed] add("Lil Nas X", "Old Town Road") add("Ed Sheeran & Justin Bieber", "I Don't Care") Expected return of size(): 3 Your size() returns: 3 Test 3: [Passed] Expected return of toString(): [Ed Sheeran & Justin Bieber - I Don't Care] [Lil Nas X - Old Town Road] [Lewis Capaldi - Someone You Loved] Your toString() returns: [Ed Sheeran & Justin Bieber - I Don't Care] [Lil Nas X - Old Town Road] [Lewis Capaldi - Someone You Loved] Test 4: [Passed] remove("Ava Max", "Sweet But Psycho") Expected: false Yours: false Test 5: [Passed] add("Ava Max", "Sweet But Psycho") add("Billie Eilish", "Bad Guy") add("Mabel", "Don't Call Me Up") add("Lewis Capaldi", "Hold Me While You Wait") Expected return of size(): 7 Your size() returns: 7 ... Test 12: [Passed] mylist.buildList("Lil Nas X") Expected return of toString() on the new list: [Lil Nas X - Old Town Road] Your toString() returns: [Lil Nas X - Old Town Road] Test 13: [Passed] mylist.buildList("Ava Max") Expected return of toString() on the new list: An empty list Your toString() returns: An empty list Total test cases: 13 Correct: 13 Wrong: 0 Programming Questions a. Completing the SongList class m_last Note that you are only supposed to touch the above methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than these four methods or files other than "SongList.java". Points will be taken off... Grading Rubrics: Sample output:
Answered Same DayMar 18, 2021

Answer To: Bad Guy Billie Eilish Old TOwn ROad Lil Nas X SOmeOne yOu lOved Lewis Capaldi CS 304 Homework...

Kshitij answered on Mar 19 2021
141 Votes
Class Song
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 18-Mar-21
* Time: 9:45 PM
* File: Song.java
*/
package March.mar18_21;
public class Song
{
// instance variables
private String m_artist;
private String m_title;
private Song m_link;
// constructor
public Song(String artist, String title)
{
m_artist = artist;
m_title = title;
m_link = null;
}
// getters and setters
public void setArtist(String artist)
{
m_artist = art
ist;
}
public String getArtist()
{
return m_artist;
}
public void setTitle(String title)
{
m_title = title;
}
public String getTitle()
{
return m_title;
}
public void setLink(Song link)
{
m_link = link;
}
public Song getLink()
{
return m_link;
}
}
Class SongList
/* Created by IntelliJ IDEA.
* Author: Kshitij Varshney (kshitijvarshne1)
* Date: 18-Mar-21
* Time: 9:47 PM
* File: SongList.java
*/
package March.mar18_21;
public class SongList {
// instance variables
private Song head;
private int m_numElements;
// constructor
// Do not make any changes to this method!
public SongList() {
head = null;
m_numElements = 0;
}
// check whether the list is empty
// Do not make any changes to this method!
boolean isEmpty() {
return head == null;
}
// return the size of the list (# of Song nodes)
// Do not make any changes to this method!
public int size() {
return m_numElements;
}
// add a new Song to the circular linked list with the given artist and
// title, keeping the list sorted by *song title*.
public void add(String artist, String title) {
m_numElements += 1;
Song newSong = new Song(artist, title);
if(isEmpty()){
head =newSong;
newSong.setLink(head);
}
else
if(title.toLowerCase().compareTo(head.getTitle().toLowerCase())<0 &&
head.getLink()==head){
Song t= head;
head= newSong;
newSong.setLink(t);
t.setLink(head);
}
else
if(title.toLowerCase().compareTo(head.getTitle().toLowerCase())>=0 &&
head.getLink()==head){
head.setLink(newSong);
newSong.setLink(head);
}
else{
Song temp = head;
Song lasAdd=head;
while(temp.getLink()!= head &&
title.toLowerCase().compareTo(temp.getTitle().toLowerCase())>=0){
lasAdd=temp;
temp=temp.getLink();
}
if(temp.getLink()==head){
temp.setLink(newSong);
newSong.setLink(head);
}
else{
newSong.setLink(lasAdd.getLink());
lasAdd.setLink(newSong);
}
}
}
// remove a Song associated with the given artist and title from the
list,
// keeping the list sorted by *song title*.
public boolean remove(String artist, String title) {
if(!isEmpty()){
if(head.getTitle().equalsIgnoreCase(title) &&
head.getArtist().equalsIgnoreCase(artist)){
Song t= head;
head=head.getLink();
Song one = head;
while(one.getLink()!=t){
one =one.getLink();
}
one.setLink(head);
return true;
}
else{
Song t=head;
t=t.getLink();
if(t.getTitle().equalsIgnoreCase(title) &&
t.getArtist().equalsIgnoreCase(artist)){
t=t.getLink().getLink();
return true;
}
Song temp1 = head;
Song lasAdd=head;
while(temp1.getLink()!= head){
lasAdd=temp1;
temp1=temp1.getLink();
}
if(lasAdd.getLink().getArtist().equalsIgnoreCase(artist) &&
lasAdd.getLink().getTitle().equalsIgnoreCase(title)){
lasAdd=head;
return true;
}
Song temp = head;
while(temp.getLink().getLink()!=head){
if(temp.getLink().getArtist().equalsIgnoreCase(artist) &&
temp.getLink().getLink()==head){
temp.setLink(head);
return true;
}
else if(temp.getArtist().equalsIgnoreCase(artist) &&
temp.getLink()!=head) {
temp.setLink(temp.getLink().getLink());
return true;
}
temp=temp.getLink();
}
}
}
return false;
}
// build and return a circular linked list that contains all songs from
the
// given artist
public SongList buildList(String artist) {
SongList newList= new SongList();
Song temp = head;
while(temp.getLink()!=head){
if(temp.getArtist().equalsIgnoreCase(artist)){
newList.add(temp.getArtist(), temp.getTitle());
}
}
return newList;
}
// return a string representation of the list
// Do not make any changes to this method!
public String toString() {
String listContent = "";
Song current = head;
if (head != null)
do {
listContent += " [" + current.getArtist() + " - " +
current.getTitle() + "]\n";...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here