I am supposed to receive an integer input first, followed by a double, followed by a string. I am then supposed to insert it into a linked list. The //TODO sections are where I implemented the code. I really don't know why I am getting these errors. I saw suggestions that said to use the useLocal() method, but it didn't help with the errors.
Here is the code:
import java.util.*;
public class MileageTrackerLinkedList {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
scnr.useLocale(Locale.US);
// 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();
}
}
}
This is the input:
3
2.2
7/2/18
3.2
7/7/18
4.5
7/16/18
And here are the error messages:
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at MileageTrackerLinkedList.main(MileageTrackerLinkedList.java:29)