# Java Gas Mileage Calculator

Question: Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by recording the miles driven and gallons used for each tankful. Develop a Java application that will input the miles driven and gallons used (both as integers) for each trip. The program should calculate and display the miles per gallon obtained for each trip and print the combined miles per gallon obtained for all trips up to this point. All averaging calculations should produce floating-point results. Use class Scanner and sentinel-controlled repetition to obtain the data from the user.
```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*
* Exercise 4.17 - Gas Mileage
*
*/

import java.util.Scanner;

public class GasMileage {

public static void main(String[] args) {

int miles;
int gallons;
int totalMiles = 0;
int totalGallons = 0;

Scanner input = new Scanner(System.in);

System.out.println("This Application Determines Calculates And Displays"
+ " The Miles Per Gallon Obtained For Each Trip And Print The"
+ " Combined Miles Per Gallon Obtained For All Trips.\n");

System.out.println("\nEnter miles driven or -1 to Quit: ");
miles = input.nextInt();

while (miles != -1 ) {
System.out.println("Enter gallons used: ");
gallons = input.nextInt();
System.out.println("\nMiles driven for this trip: " + miles);
System.out.println("Gallons used for this trip: " + gallons);
totalMiles += miles;
totalGallons += gallons;
System.out.printf("\nMiles per gallon for this trip: %f\nCombined Miles "
+ "per gallon: %f\n",(double)miles/gallons, (double)totalMiles/totalGallons);

System.out.println("\nEnter miles driven or -1 to Quit: ");
miles = input.nextInt();
}
System.out.println();
}
}
```

 Program Output