• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Compilation error making a playlist

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got code for making a playlist. But when I submit to the compiler for grading I get a compilation error. I don't know how to fix it. Can someone help please?


Here is one part. Other to follow. will run in Eclipse, but not ZyBooks.

[/code]



 
S. Eckstrom
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update: Sorry just noticed I posted the same code twice. Here is the 2nd part. Thanks for any help.

 
Sheriff
Posts: 15801
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the error message carefully. It shows an attempt to use a constructor that takes only 4 parameters. The constructors you have defined take 0 and 5 parameters respectively.
 
S. Eckstrom
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured I would post the assignment instructions to help clarify if there were any questions of what needs to be done.

Assignment:
You will be building a linked list. Make sure to keep track of both the head and tail nodes.

(1) Create two files to submit.

   SongEntry.java - Class declaration
   Playlist.java - Contains main() method

Build the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.

   Private fields
   String uniqueID - Initialized to "none" in default constructor
   string songName - Initialized to "none" in default constructor
   string artistName - Initialized to "none" in default constructor
   int songLength - Initialized to 0 in default constructor
   SongEntry nextNode - Initialized to null in default constructor
   Default constructor (1 pt)
   Parameterized constructor (1 pt)
   Public member methods
   void insertAfter(SongEntry currNode) (1 pt)
   void setNext(SongEntry nextNode) - Mutator (1 pt)
   String getID()- Accessor
   String getSongName() - Accessor
   String getArtistName() - Accessor
   int getSongLength() - Accessor
   SongEntry getNext() - Accessor
   void printPlaylistSongs()

Ex. of printPlaylistSongs output:

Unique ID: S123
Song Name: Peg
Artist Name: Steely Dan
Song Length (in seconds): 237

(2) In main(), prompt the user for the title of the playlist. (1 pt)

Ex:

Enter playlist's title:
JAMZ


(3) Implement the printMenu() method. printMenu() takes the playlist title as a parameter and a Scanner object, outputs a menu of options to manipulate the playlist, and reads the user menu selection. Each option is represented by a single character. Build and output the menu within the method.

If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call printMenu() in the main() method. Continue to execute the menu until the user enters q to Quit. (3 pts)

Ex:

JAMZ PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit

Choose an option:


(4) Implement "Output full playlist" menu option. If the list is empty, output: Playlist is empty (3 pts)

Ex:

JAMZ - OUTPUT FULL PLAYLIST
1.
Unique ID: SD123
Song Name: Peg
Artist Name: Steely Dan
Song Length (in seconds): 237

2.
Unique ID: JJ234
Song Name: All For You
Artist Name: Janet Jackson
Song Length (in seconds): 391

3.
Unique ID: J345
Song Name: Canned Heat
Artist Name: Jamiroquai
Song Length (in seconds): 330

4.
Unique ID: JJ456
Song Name: Black Eagle
Artist Name: Janet Jackson
Song Length (in seconds): 197

5.
Unique ID: SD567
Song Name: I Got The News
Artist Name: Steely Dan
Song Length (in seconds): 306


Ex (empty playlist):

JAMZ - OUTPUT FULL PLAYLIST
Playlist is empty


(5) Implement the "Add song" menu item. New additions are added to the end of the list. (2 pts)

Ex:

ADD SONG
Enter song's unique ID:
SD123
Enter song's name:
Peg
Enter artist's name:
Steely Dan
Enter song's length (in seconds):
237


(6) Implement the "Remove song" method. Prompt the user for the unique ID of the song to be removed.(4 pts)

Ex:

REMOVE SONG
Enter song's unique ID:
JJ234
"All For You" removed


(7) Implement the "Change position of song" menu option. Prompt the user for the current position of the song and the desired new position. Valid new positions are 1 - n (the number of nodes). If the user enters a new position that is less than 1, move the node to the position 1 (the head). If the user enters a new position greater than n, move the node to position n (the tail). 6 cases will be tested:

   Moving the head node (1 pt)
   Moving the tail node (1 pt)
   Moving a node to the head (1 pt)
   Moving a node to the tail (1 pt)
   Moving a node up the list (1 pt)
   Moving a node down the list (1 pt)

Ex:

CHANGE POSITION OF SONG
Enter song's current position:
3
Enter new position for song:
2
"Canned Heat" moved to position 2


(8) Implement the "Output songs by specific artist" menu option. Prompt the user for the artist's name, and output the node's information, starting with the node's current position. (2 pt)

Ex:

OUTPUT SONGS BY SPECIFIC ARTIST
Enter artist's name:
Janet Jackson

2.
Unique ID: JJ234
Song Name: All For You
Artist Name: Janet Jackson
Song Length (in seconds): 391

4.
Unique ID: JJ456
Song Name: Black Eagle
Artist Name: Janet Jackson
Song Length (in seconds): 197


(9) Implement the "Output total time of playlist" menu option. Output the sum of the time of the playlist's songs (in seconds). (2 pts)

Ex:

OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)
Total time: 1461 seconds

Submission Instructions
Compile command
javac Playlist.java SongEntry.java -Werror
We will use this command to compile your code
 
S. Eckstrom
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar, so should I remove the "this.nextNode = null;" on line 25 and the "this.nextNode = nextNode;" on line 39?
 
Junilu Lacar
Sheriff
Posts: 15801
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It appears this test is expecting the SongEntry class to have a constructor that takes 4 parameters. Count them. "SD123", "Peg", "SteelyDan", and 237. That's four parameters the test is trying to pass. As I said earlier, you appear to only have two constructors for SongEntry, one that takes zero parameters and another that takes five parameters.  There's no constructor that takes only four parameters.  This is why you get a compiler error, because your implementation does not conform to the contract that the test seems to be checking: that you should be able to create a SongEntry object using a constructor that takes four parameters.

What you need to do is provide a constructor that takes four parameters.
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic