Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java method to make this program work.The driver class provided will gui

ID: 672054 • Letter: W

Question

Write a java method to make this program work.The driver class provided will guide on the name and parameters of the method. Create a class(named Steady) in which the method will reside rather than modify the linkedlist. The method must make use of the Node/linkedlist framework provided. Arrays should not be used. The rest are used to construct the list upon which the method is performed.

import java.util.Scanner;
//
public class Test {
  
private Test() { /* Class does not define a type of object. */}
  
private static void loadList(final Scanner scanner, final LinkedList list) {
if (scanner.hasNextInt()) {
final int value = scanner.nextInt();
loadList(scanner, list);
list.add(value);
}
}
  
public static void main(final String[] args) {
  
// Create a scanner that processes a single line of input.
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextLine()) { scanner = new Scanner(scanner.nextLine());}
  
// First value is a test argument to be used in the method.
final int testArgX = scanner.nextInt();
// Second value is a test argument to be used in the method.
final int testArgY = scanner.nextInt();
  
  
// Rest of the values form the list.
final LinkedList list = new Solution();
loadList(scanner, list);
  
scanner.close();
  
// Print list.
System.out.println("List: "+list);
// Execute method and print result.
System.out.print("The number of values greater than "+testArgX+" and less than "+testArgY+" is ");
final int num = ((Solution)list).numInRange(testArgX, testArgY);
System.out.println(num+".");
}
}

public class Node {
private int data;
private Node next;

Node(int number) { data=number; }

public Node getNext() { return next; }
public void setNext(Node n) { next=n; }
public boolean hasNext() { return next!=null; }

public int getData() { return data; }
public void setData(int number) { data=number; }   

public String toString () { return ""+data; }
}

public class LinkedList {
protected Node head;

public LinkedList () { head = null; }

public void add ( int number ) {
Node t = new Node (number);
t.setNext (head);
head = t;
}

public String toString () {
Node t = head;
if (t==null) {
return "";
}
else {
String list = t.toString();
while (t.hasNext()) {
t=t.getNext();
list=list+" "+t.toString();
}
return list;
}
}
}

Explanation / Answer

class Node
{
Node next;
int num;
public Node(int val)
{
num = val;
next = null;
}
}
class LinkedList
{
private Node head = null;
public void append(int val)
{
Node lastNode = getLastNode();
if (lastNode == null)
{
head = new Node(val);
}
else
{
lastNode.next = new Node(val);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote