Write a java method to make this program work.The driver class provided will gui
ID: 672285 • 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.
Sample i/o:
list: 3
range: 5
Sample i/o:
list: 5 2 4 6 73
range: 5
Sample i/o:
list: 7 19 15 18 8 7
range: 12
Sample i/o:
list: 7 7 7 7 7 7
range: 0
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((new Scanner(System.in)).nextLine());
// Load input values into the list.
final LinkedList list = new Solution();
loadList(scanner, list);
scanner.close();
// Print list.
System.out.println("List: "+list);
// Execute method and print result.
int result = ((Solution)list).getRange();
System.out.println("Range: "+result);
}
}
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; }
}
import java.util.Scanner;
//
public class Test3M {
private Test3M() { /* 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((new Scanner(System.in)).nextLine());
// Load input values into the list.
final LinkedList list = new Solution();
loadList(scanner, list);
scanner.close();
// Print list.
System.out.println("List: "+list);
// Execute method and print result.
int result = ((Solution)list).getRange();
System.out.println("Range: "+result);
}
}
Explanation / Answer
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((new Scanner(System.in)).nextLine());
// Load input values into the list.
final LinkedList list = new Solution();
loadList(scanner, list);
scanner.close();
// Print list.
System.out.println("List: "+list);
// Execute method and print result.
int result = ((Solution)list).getRange();
System.out.println("Range: "+result);
}
}
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; }
}
import java.util.Scanner;
//
public class Test3M {
private Test3M() { /* 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((new Scanner(System.in)).nextLine());
// Load input values into the list.
final LinkedList list = new Solution();
loadList(scanner, list);
scanner.close();
// Print list.
System.out.println("List: "+list);
// Execute method and print result.
int result = ((Solution)list).getRange();
System.out.println("Range: "+result);
}
}
Please provide more details on what you would like to perform with this code.and get the O/P as below
Sample i/o:
list: 3
range: 5
Sample i/o:
list: 5 2 4 6 73
range: 5
Sample i/o:
list: 7 19 15 18 8 7
range: 12
Sample i/o:
list: 7 7 7 7 7 7
range: 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.