Question: Instructor note: Use the next ( ) method when scanning the date. date = scnr . next ( ) ; Given the MileageTrackerNode class, complete
Instructor note:
Use the next method when scanning the date.
date scnrnext;
Given the MileageTrackerNode class, complete main in the MileageTrackerLinkedList class to insert nodes into a linked list using the insertAfter method The first userinput 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:
the output is:
import java.util.Scanner;
public class MileageTrackerLinkedList
public static void main String args
Scanner scnr new ScannerSystemin;
References for MileageTrackerNode objects
MileageTrackerNode headNode;
MileageTrackerNode currNode;
MileageTrackerNode lastNode;
double miles;
String date;
int i;
Front of nodes list
headNode new MileageTrackerNode;
lastNode headNode;
try
Scan the number of nodes
numNodes scnrnextInt;
For the scanned number of nodes, scan
in data and insert into the linked list
for int i ; i numNodes; i
miles scnrnextDouble;
date scnrnext;
currNode new MileageTrackerNodemiles date;
lastNode.insertAftercurrNode;
lastNode currNode;
Call the printNodeData method
to print the entire linked list
currNode headNode.getNext;
while currNode null
currNode.printNodeData;
currNode currNode.getNext;
catch Exception e
System.out.printlnInput error: egetMessage;
finally
scnrclose;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
