Given the MileageTrackerNode class, complete main() in the MileageTrackerLinkedList class to insert nodes into a linked list (using the insertAfter() method). The first user-input value is the number of nodes in the linked list. Use the printNodeData() method to print the entire linked list. DO NOT print the dummy head node.
Ex. If the input is:
3
2.2
7/2/18
3.2
7/7/18
4.5
7/16/18
the output is:
2.2, 7/2/18
3.2, 7/7/18
4.5, 7/16/18
I just need to edit the //TO DO sections, but have also added int count Error messages:
Exception in thread "main" java.util.InputMismatchException
java.base/java.util.Scanner.throwFor(Scanner.java:939)
java.base/java.util.Scanner.next(Scanner.java:1594)
java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
MileageTrackerLinkedList.main(MileageTrackerLinkedList.java:28)
Here is my code so far:
import java.util.Scanner;
public class MileageTrackerLinkedList {
public static void main (String[] args) {
Scanner scnr = new Scanner(System.in);
// References for MileageTrackerNode objects
MileageTrackerNode headNode;
MileageTrackerNode currNode;
MileageTrackerNode lastNode;
double miles;
String date;
int i;
int count;
// Front of nodes list
headNode = new MileageTrackerNode();
lastNode = headNode;
// TODO: Scan the number of nodes
count = scnr.nextInt();
// TODO: For the scanned number of nodes, scan
// in data and insert into the linked list
for (i = 0; i < count; ++i) {
miles = scnr.nextDouble();
date = scnr.nextLine();
currNode = new MileageTrackerNode(miles, date);
lastNode.insertAfter(currNode);
lastNode = currNode;
}
// TODO: Call the printNodeData() method
// to print the entire linked list
for (i = 0; i < count; ++i) {
headNode.printNodeData();
headNode.getNext();
}
}
}