-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPG.java
35 lines (26 loc) · 860 Bytes
/
MPG.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//MPG.java
import java.util.Scanner; //Needed for the Scanner class
/**
This program calculate a vehicle's miles per gallon.
*/
public class MPG
{
public static void main(String[] args)
{
double miles; //Miles the vehicle was driven
double gallons; //Gallons of fuel consumed
double mpg; //Calculated MPGs
//Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
//Get the miles driven
System.out.print("How many miles were driven? ");
miles = keyboard.nextDouble();
//Get the gallons of fuel consumed
System.out.print("How many gallons of fuel were consumed? ");
gallons = keyboard.nextDouble();
//Compute the total sale
mpg = (miles/gallons);
//Display the resulting information.
System.out.println("Miles per gallon: " + mpg );
}
}