In: Computer Science
1a) Write the start of the class declaration for a node in a linked list (give the name of the class and the instance variables). The name of the node should be SpecialNode. The data in each SpecialNode will include both a String and a Song object.
b)Using the SpecialNode class you created in question above, write a constructor forSpecialNode that has three parameters and initializes all the SpecialNode instance variables.
c) Write a line of code to instantiate a SpecialNode object to initialize the SpecialNodeinstance variables. Use the constructor you wrote in the previous question.
Song rockstar = new Song("Rockstar", 5);
SpecialNode sn = ___________________________________ ;
Short Summary:
Song.java File:
public class Song {
private String name;
private int rating;
Song(String name, int rating){
this.name = name;
this.rating = rating;
}
}
SpecialNode.java File:
public class SpecialNode {
private String data;
private Song song;
private SpecialNode next;
// Constructor to create a new node
SpecialNode(String data, Song song, SpecialNode next) {
this.data = data;
this.song = song;
this.next = next;
}
}
LinkedListTest.java File:
public class LinkedListTest {
public static void main(String[] args) {
Song rockstar = new
Song("Rockstar", 5);
SpecialNode sn = new
SpecialNode("MyList", rockstar, null);
}
}
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************