Calculate car filled up times
- by Ivan
Here is the question:
The driving distance between Perth and Adelaide is 1996 miles.
On the average, the fuel consumption of a 2.0 litre 4 cylinder car is 8 litres per 100 kilometres.
The fuel tank capacity of such a car is 60 litres.
Design and implement a JAVA program that prompts for the fuel consumption and fuel tank capacity of the aforementioned car.
The program then displays the minimum number of times the car’s fuel tank has to be filled up to drive from Perth to Adelaide. Note that 62 miles is equal to 100 kilometres.
What data will you use to test that your algorithm works correctly?
Here is what I've done so far:
import java.util.Scanner;//
public class Ex4{
public static void main( String args[] ){
Scanner input = new Scanner( System.in );
double distance, consumption, capacity, time;
distance = Math.sqrt(1996/62*100);
consumption = Math.sqrt(8/100);
capacity = 60;
time = Math.sqrt(distance*consumption/capacity);
System.out.println("The car's fuel tank need to be filled up:" + time + "times");
}
}
I can compile it but the problem is that the result is always 0.0, can anyone help me what's wrong with it ?