Question
java

Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic. The class has one class at
one being a Node<T> with the variable name next. a. Add this new class attribute to both of the Constructors assigning the va
Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic. The class has one class attribute that is an element. It will need 2 Constructors, a setter and getter for the class attribute, and a toString method. 2. Write a Lab10Driver that will: Instantiate a Node Integer object with no value. I. Il. Ill. IV. a. Then call the set method to set the value to 5. Instantiate a Node String object with no value. a. Then call the set method to set the value of Daryn. Instantiate a Node Double object using the non-empty Constructor to set the value to 7.34 Instantiate an ArrayList that is of Node data type (if you want to get rid of the yellow line under Nodes here, add the suppression warring of "rawtypes") and add a. A Node Integer with the value of 8 b. A Node String with a value of Tia C. A Node Double with the value of 16.68 V. Call the toString method for every object ard the ArrayList. 3. Go back to your Node class and add another class attribute, this one being a Node with the variable name next. a. Add this new class attribute to both of the Constructors assigning the value of null. b. Create a setter and getter for this new class attribute. c. Add the new class attribute to your toString 4. In the Lab10Driver 1205 PM rP ^ dx 4/11/2019
one being a Node with the variable name next. a. Add this new class attribute to both of the Constructors assigning the value of null b. Create a setter and getter for this new class attribute. c. Add the new class attribute to your toString. 4. In the Lab10Driver: I. II. Ill. In SOPIn's: Instantiate a new Node Integer using the non-empty Constructor to set the value to 20 Use the Node you just instantiated and call the setNext method passing a new Node with the value of Sue. i. Call the tostring method for the Node from Part 3 ii. Call the getNext method on the Node from Part 3 Notice how the data is printed for a Node verse a next Node. Be sure to have a TA grade your work using the queue system and submit your work to Blackboard or you will not receive a grade
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question, here is generic class Node.java and the driver class. If you run the program it will output

5

Daryn

7.34

8

Tia

16.68

20, next: Sue

==========================================================================================

//Question 1
public class Node<T> {

    private T element;
    // Question 3
   
private Node next;

    public Node(T element) {
        this.element = element;
        next = null; // 3.a
   
}

    public Node() {
        this.element = null;
        next = null; // 3.a
   
}

    public T getElement() {
        return element;
    }

    public void setElement(T element) {
        this.element = element;
    }

    @Override
    public String toString() {
        if (next==null)
        return this.element.toString() ;
        else // 3.c
           
return this.element.toString() + ", next: " + next.toString();
    }

    // 3.b
   
public Node getNext() {
        return next;
    }
    // 3.b
   
public void setNext(Node next) {
        this.next = next;
    }
}

==========================================================================================

import java.util.ArrayList;



public class Lab10Driver {



    public static void main(String[] args) {



        // Question 2 I, II, III

        Node<Integer> intNode = new Node<>();

        intNode.setElement(5);

        Node<String> strNode = new Node<>();

        strNode.setElement("Daryn");

        Node<Double> dblNode = new Node<>();

        dblNode.setElement(7.34);



        // Question IV

        ArrayList<Object> nodeData = new ArrayList();

        nodeData.add(new Node<>(8));

        nodeData.add(new Node<>("Tia"));

        nodeData.add(new Node<>(16.68));



        // question V

        System.out.println(intNode);

        System.out.println(strNode);

        System.out.println(dblNode);



        for(Object obj : nodeData){

            System.out.println(obj);

        }



        // 4 I

        Node<Integer> integerNode = new Node<>(20);

        // 4 II

        integerNode.setNext(new Node<>("Sue"));

        // 4 III

        System.out.println(integerNode);





    }

}
Add a comment
Know the answer?
Add Answer to:
Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property...

    PYTHON Task 1 Create a class called Window It has 2 public properties 1 private property 1 constructor that takes 3 arguments pass each argument to the appropriate property Task 2 In a new file import the Window class Instantiate the Window object Output the two public properties Task 3 Alter the Window class in Task 1 Add an accessor and mutator (the ability to access and change) to the private property Task 4 Create a class named Instrument Give...

  • Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that...

    Java programming: please help with the following assignment: Thank you. Create a class called GiftExchange that simulates drawing a gift at random out of a box. The class is a generic class with a parameter of type T that represents a gift and where T can be a type of any class. The class must include the following An ArrayList instance variable that holds all the gifts,The ArrayList is referred to as theBox. A default constructors that creates the box....

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • JAVA Create a Java project to implement a simple Name class. This class will have the...

    JAVA Create a Java project to implement a simple Name class. This class will have the following class variable: First Name, Middle Name, Last Name, and Full Name Create the accessor/getter and mutator/setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Create a main() method to test your project.

  • Define a public method that is called isPrime() that returns a boolean and implements the Sieve...

    Define a public method that is called isPrime() that returns a boolean and implements the Sieve of Eratosthenes method. Define a public method that is called numberOfPrimes() that returns the number of prime numbers between 2 and the private attribute value. Show this object in a main method that allows the user to interact with all the public methods of your class. Make a class called MyNumber with an integer private attribute. Make a constructor that defines an integer parameter...

  • List of Candles Create a class called CandleNode which has fields for the data (a Candle)...

    List of Candles Create a class called CandleNode which has fields for the data (a Candle) and next (CandleNode) instance variables. Include a one-argument constructor which takes a Candle as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures”.) public CandleNode (Candle c) { . . } The instance variables should have protected access. There will not be any get and set methods for the two instance variables. Create an abstract linked list class called CandleList. This...

  • In Java* Please implement a class called "MyPet". It is designed as shown in the following...

    In Java* Please implement a class called "MyPet". It is designed as shown in the following class diagram. Four private instance variables: name (of the type String), color (of the type String), gender (of the type char) and weight(of the type double). Three overloaded constructors: a default constructor with no argument a constructor which takes a string argument for name, and a constructor with take two strings, a char and a double for name, color, gender and weight respectively. public...

  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT