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); } }
Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic...
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 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 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 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 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 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 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) 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 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 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...