Al's Last Chance Gas station sits on Route 190 on the edge of Death Valley. There is no other gas station for 200 miles.
You are to write a program to help drivers decide if they need gas. The program asks for:
|
There are 3 things to know so you should declare 3 variables: int cap; |
And 1 thing to calculate: int distance; |
| The program then writes out "Get Gas" or "Safe to Proceed" depending on if the car can cross the 200 miles with the gas remaining in the tank. |
Calculate how far the car can go with the gas you have: Multiply cap X gage X mpg divided by 100 = distance you can travel |
|
Translate this to Java: if you can go < 200 miles print "Get Gas!" |
||
Sample run of the program:
Tank capacity: 12
Gage reading: 50
Miles per gallon: 30
Get Gas! ---------------------------------------------------- Also test it with a tank capacity of 20 gallons, 50 percent full, 20 mpg (just enough to make the trip) Try a tank that holds 25 gallons, is 75% full in a truck that only gets 12 miles to the gallon.