Question: Miles per gallon (MPG) calculation. Given a file containing data about the miles driven and the gallons of gas used per trip, write a Java

Miles per gallon (MPG) calculation. Given a file containing data about the miles driven and the gallons of gas used per trip, write a Java program that calculates the MPG per trip and overall MPG. Sample input file as below: 350 12.3 200 10.1 500 18.7

Each line contains the miles driven and gallons used for a single trip. The input file name must be given through the first command line argument args[0]. The output for the above input should look like below:

Trip 1: 28.5 Trip 2: 19.8 Trip 3: 26.7 Overall: 25.5

The output has to be written into a file. The output file name is given through the second command line arguments args[1].

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!