Question

In: Computer Science

Use this code to answer the following questions:           Object obj;           String str;           Song...

Use this code to answer the following questions:

          Object obj;

          String str;

          Song sng = new Song("Rockstar", 5);

          obj = sng;              // #7

          sng = str;              // #8

          str = (String) obj;     // #9

          sng = obj;              // #10

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 #11, 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 = ___________________________________ ;

Solutions

Expert Solution

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.

Ans:

Class SpecialNode {

String str;

Object obj;

obj sng;

}

b)  Using the SpecialNode class you created in question #11, write a constructor forSpecialNode that has three parameters and initializes all the SpecialNode instance variables.

Ans: SpecialNode(string,object,song) {

str = string;

obj = object;

sng = song;

}

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 = new SpecialNode("Rockstar",6,rockstar);

//Here, we took 3 parameters, so Rockstar is a string, 6 is an object, and rockstar is the Song which is already defined in the question (Song rockstar = new Song("Rockstar", 5))

Note: If you have any related doubts, queries, feel free to ask by commenting down below.

And if my answer suffice your requirements, then kindly upvote.

Happy Learning


Related Solutions

using java language only write a code Have the function StringChallenge(str) take the str string parameter...
using java language only write a code Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3 ------- you have the following code edit it to get the result mport java.util.*; import java.io.*; class Main {   public static String StringChallenge(String str)...
Consider the following code used to read a file. byte[] buffer = new byte[BUFFER_SIZE]; String str...
Consider the following code used to read a file. byte[] buffer = new byte[BUFFER_SIZE]; String str = ""; try { while (true) { int read = infile.read(buffer); if (read <= 0) { break; } str += new String(buffer, 0, read); } } catch (IOException ex) { return; } Consider if BUFFER_SIZE is set to 1000 and the the file is 2775 bytes long. How many times will infile.read() be called? What value will infile.read() return on the next to last...
Create a class, called Song. Song will have the following fields:  artist (a string) ...
Create a class, called Song. Song will have the following fields:  artist (a string)  title (a string)  duration (an integer, recorded in seconds)  collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration....
Please read and understand the following program code. Use it to answer the following 4 questions....
Please read and understand the following program code. Use it to answer the following 4 questions. #include <iostream> #include <string> #include <sstream> using namespace std; class timeStamp // uses 24-hour times (0..24) { public:     timeStamp(void);     timeStamp(int, int, int);     void setTime(int, int, int);     timeStamp *addTimes(timeStamp *);     timeStamp *subTimes(timeStamp *);     string toString(void);     int hour;     int minute;     int second; }; int main() {     timeStamp noon(12, 0, 0);     timeStamp *teaTime = new timeStamp(51,...
Question 3. In the following code, answer these questions: Analyze the code and how it works?...
Question 3. In the following code, answer these questions: Analyze the code and how it works? How can we know if this code has been overwritten? Justify how? #include <stdlib.h> #include <unistd.h> #include <stdio.h> int main(int argc, char **argv) { int changed = 0; char buff[8]; while (changed == 0){ gets(buff); if (changed !=0){ break;} else{     printf("Enter again: ");     continue; } }      printf("the 'changed' variable is modified\n %d", changed); } END of the questions :::::::::::::::::::::::::: :::::::::::::::::::::::::: Submission...
2. Answer the following questions about the motion of an object launched from the roof of...
2. Answer the following questions about the motion of an object launched from the roof of a building with a height of 10 m at an initial velocity of 20 m/s and an angle of 60°. (1) Find the x and y components of the initial velocity. (2) Find the x and y components of the velocity after 2.0 seconds. (3) Find the time to reach the highest point. (4) Find the height of the highest point. (5) Find the...
  Answer the questions related to the following code:             Class B             {      &nbs
  Answer the questions related to the following code:             Class B             {                         Public:                                     Void b1();                         Protected:                                     Void b2();             };             Class A : public B             {                         Public:                                     Void  a1();                         Protected: Void  a2();             };             Class C: public A               {                         Public:                                     Void c1();             }; Void main () { B temp1; A temp2; C temp3; }    Name all member functions of all classes visible through temp1 in the main function? Name all member functions of all classes visible through temp2 in the main function? Name all...
Use the following information to answer the questions below:
Use the following information to answer the questions below: note: all sales are credit sales Income Stmt info: 2016 2017 Sales $ 975,000 $        1,072,500 less Cost of Goods Sold: 325,000 346,125 Gross Profit 650,000 726,375 Operating Expenses 575,000 609,500 Earnings before Interest & Taxes 75,000 116,875 Interest exp 25,000 31,000 earnings before Taxes 50,000 85,875 Taxes 20,000 34,350 Net Income $ 30,000 $              51,525 Balance Sheet info: 12/31/2016 12/31/2017 Cash 60,000 $ 63,600 Accounts Receivable 80,000 $ 84,000 Inventory...
Use the following data to answer the questions below:
Use the following data to answer the questions below:             Q                 VC             MC           AVC              1                 $10              ___            ___                                   2                16              ___            ___                       3                20              ___            ___                                   4                25              ___            ___              5                31              ___            ___              6                  38              ___            ___                  7                  46              ___            ___8                  55              ___            ___9                  65              ___            ___         a. Calculate the marginal cost and average variable cost for each level of production.b. How much would the firm produce if it could sell its product for...
Compile and run the following code then answer the following questions: a.) Run this command from...
Compile and run the following code then answer the following questions: a.) Run this command from the shell prompt: ./a.out ls -F Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Be sure to comment on the pointer arithmetic done inside the line: execvp(*(argv+1), argv+1); b.) Run this command from the shell prompt:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT