Question: Something wrong with the code, I don't know what the problem, but gradescope keep saying constructor SongList in class SongList cannot be applied to given
Something wrong with the code, I don't know what the problem, but gradescope keep saying constructor SongList in class SongList cannot be applied to given types; private SongList songListUnderTest = new SongList(); required: String found: no arguments reason: actual and formal argument lists differ in length package cmsc256; import bridges.base.SLelement; import java.util.Iterator; public class SongList implements List,Iterable { private String PlayListName; private SLelement theSong; private int numSongs; public SongList(String name) { PlayListName = name; theSong = null; numSongs = 0; } @Override public boolean insert(MySong it, int position){ if (position < 0 || position > numSongs) { throw new IllegalArgumentException("Invalid position"); } SLelement newSong = new SLelement<>(it.getSongTitle(), it); if (position == 0) { newSong.setNext(theSong); theSong = newSong; } else { SLelement prev = theSong; for(int i = 0; i < position - 1; i++){ prev = prev.getNext(); } newSong.setNext(prev.getNext()); prev.setNext(newSong); } numSongs++; return true; } @Override public boolean add(MySong it) { SLelement newSong = new SLelement<>(it.getSongTitle(), it); if (theSong == null) { theSong = newSong; } else { SLelement last = theSong; while(last.getNext() != null) { last = last.getNext(); } last.setNext(newSong); } numSongs++; return true; } @Override public MySong remove(int position){ if (position < 0 || position >= numSongs) { throw new IllegalArgumentException("Invalid position"); } MySong removedEntry; if (position == 0) { removedEntry = theSong.getValue(); theSong = theSong.getNext(); } else { SLelement current = theSong; for (int i = 0; i < position - 1; i++) { current = current.getNext(); } removedEntry = current.getNext().getValue(); current.setNext(current.getNext().getNext()); } numSongs--; return removedEntry; } @Override public void clear() { theSong = null; numSongs = 0; } @Override public int size() { return numSongs; } @Override public boolean isEmpty() { if (numSongs == 0) { return true; } return false; } @Override public boolean contains(Object target) { SLelement current = theSong; while (current != null) { if (current.getValue().equals(target)) { return true; } current = current.getNext(); } return false; } @Override public MySong getValue(int position) { if (position < 0 || position >= numSongs) { throw new IllegalArgumentException("Index: " + position + ", Size: " + numSongs); } SLelement current = theSong; for (int i = 0; i < position; i++) { current = current.getNext(); } return current.getValue(); } @Override public Iterator iterator() { return new SongList.SongIterator(theSong); } public String getSongsByArtist(String artist) { StringBuilder sb = new StringBuilder(); boolean found = false; for (MySong song : this) { if (song.getArtist().equals(artist)) { found = true; sb.append("Title: " + song.getSongTitle() + " Album: " + song.getAlbumTitle() + " "); } } if (!found) { sb.append("There are no songs by " + artist + " in this playlist."); } return sb.toString(); } private class SongIterator implements Iterator { private SLelement current; public SongIterator(SLelement head) { current = head; } @Override public boolean hasNext() { return current != null; } @Override public MySong next() { if (!hasNext()) { throw new IllegalArgumentException(); } MySong song = current.getValue(); current = current.getNext(); return song; } } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
