Calculate car filled up times

Posted by Ivan on Stack Overflow See other posts from Stack Overflow or by Ivan
Published on 2010-03-20T09:02:51Z Indexed on 2010/03/20 9:11 UTC
Read the original article Hit count: 385

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about homework

Related posts about exercise