+ 1

Textbook Exercise Question (Java)

Hi guys, I don't understand what the following exercise is asking for me to do at all. I'd appreciate your help. This exercise is from "The Java Programming Language, Fourth Edition" by Ken Arnold, James Gosling, and David Holmes. "Exercise 2.2: Write a LinkedList class that has a field of type Object and a reference to the next LinkedList element in the list." If anyone understands what the exercise is asking me to do, please let me know! Peter

15th Feb 2017, 10:10 PM
Peter Hubbard
Peter Hubbard - avatar
3 Respuestas
+ 2
I think you have to write a code for a list in which every element has an Object element and a pointer for the next element. Example struct Element{ Object obj; LinkedList* next; // You should consider making a constructor for this structure, as it will help you in later use Element(const Object& a, LinkedList* next=nullptr): obj(a),next(next) {} } I hope this helps :) Edit: I have written this code in C++. I just started Java and havent realized that they have different syntax for creating a list. The poin is, you want to have a class or a structure to represent one element of the list and within that element you want to have a pointer to point to the location of the next one. I think that in java you can use classes for this instead of structures
15th Feb 2017, 10:32 PM
Milos Milisavljevic
Milos Milisavljevic - avatar
+ 1
Thanks for your response! I think I figured it out.
16th Feb 2017, 2:11 AM
Peter Hubbard
Peter Hubbard - avatar
0
Complete the given program to print "Java is fun". Note that the sentence starts with a capital letter. Hint Just add the text to the System.out.println() method
4th Oct 2021, 11:23 AM
Yogendra