Menu
Question Index
...

What will be the output of the following program?

public class ElectricityBill {

    static double surcharge = 50.0;

    public static void main(String[] args) {
        ElectricityBill eb = new ElectricityBill();
        System.out.print(eb.amount(500, 200) + "~");
        System.out.print(eb.amount(600, 500) + "~");
        System.out.print(eb.amount(1000, 600));
    }

    int amount(int current, int previous) {
        int difference = current - previous;
        double charges = surcharge;
        if (difference > 300) {
            charges += (difference - 300) * 6.0;
            difference = difference - 300;
        }
        if (difference > 100) {
            charges += (difference - 100) * 4.5;
            difference = difference - 100;
        }
        charges += difference * 3.0;
        return (int) charges;
    }
}


50~50~650
1250~350~1850
1550~350~950
Some other output or Compilation Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App