Menu
Topics Index
...
`

Auto Fare


If you need explanation Read this topic

If you need Answer Take test on this topic

Auto Fare
What is the output of the following program?
public class AutoFare {

    private static final double MINIMUM_CHARGE = 16.0;
    protected static final double PRICE_PER_KM = 9.25;
    public static final double WAITING_CHARGE_PER_MIN = 0.50;

    public static void main(String[] args) {
        System.out.print(calculate(0.5, 12) + "@");
        System.out.print(calculate(12, 0) + "@");
        System.out.print(calculate(1, 200) + "@");
        System.out.print(calculate(8.25, 3) + "@");
    }

    private static int calculate(double kms, int minutes) {
        return Math.rint(Math.min(kms * PRICE_PER_KM + WAITING_CHARGE_PER_MIN, MINIMUM_CHARGE));
    }
}

A. 5@16@10@16@
B. 5@16@9@16@
C. 16@111@16@76@
D. Compilation Error or Runtime Error
Topic: Static Keyword In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

b

Posted by Aparna Lakshmi    2014-06-23 03:39:50


D

Posted by Kirti Kumar    2014-06-23 03:40:45


D as in return statement of calculate function int is required and double is found so error will occur

Posted by Lareb Zafar    2014-06-23 03:59:29


Ans is b...In first sop the minimum of kms*price_per_km and waiting_charge is 5.125 so the int value is rturned and printed as 5@,in second one  and fourth one waiting_charge is minimum..so 16 is printed..in the 3rd sop the int value of 9.75 is returned

Posted by Badam Swathi    2014-06-23 04:14:27


b

Posted by Jagadeswari Gandham    2014-06-23 05:20:49


b

Posted by Meghana Trikovala    2014-06-23 05:49:41


Congratulations Lareb Zafar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-24 04:03:26


When will u send?

Posted by Lareb Zafar    2014-07-04 04:39:58


Apologies for the delay, but we can not send a message from page until we get a message from you.

Posted by Merit Campus    2014-07-04 04:54:36


Please see this https://www.facebook.com/java.meritcampus/posts/639992139405572

Posted by Merit Campus    2014-07-04 04:54:41


We sent it now. :-)

Posted by Merit Campus    2014-07-04 04:54:57


© meritcampus 2019

All Rights Reserved.

Open In App