Can someone help me Write a program TravelLog.java that reads in two file names
ID: 3664978 • Letter: C
Question
Can someone help me Write a program TravelLog.java that reads in two file names from a keyboard Scanner. It then reads the contents of the first file (a "travel log file"), which is a list of road names followed by a series of numbers that represent distances, in miles, of trips on that road over some time period. For each road, an entry is written to the output file (a "travel summary file") with the road name followed by the total distance traveled on that road during the given period. A grand total distance traveled is written on the last line of the travel summary file.
Explanation / Answer
sample file: import java.util.Scanner; // Needed for using Scanner import java.io.File; // Needed for file operation import java.io.FileNotFoundException; // Needed for file operation public class TextFileScannerWithThrows { public static void main(String[] args) throws FileNotFoundException { // Declare "throws" here int num1; double num2; String name; Scanner in = new Scanner(new File("travel_Log.txt")); // Scan input from text file name = in.nextString(); // Read int num1 = in.nextDouble(); // Read double num2 = in.next(); // Read String System.out.printf( name, num1, num2,); in.close(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.