Question #5038

The Universe Energy electric company calculates electricity charges based upon usage. The normal rate is RM0.50 per Kilowatt Hour (KWH) for the first 1000 KWH. If the number of KWH is above 1000, then the balance from normal rate is charged for RM0.40 per KWH. Write a CalculateBill class that consists of only one method named calculate() to calculate and return the electricity charge.

Then, write one other class named DemoCalculateBill to demonstrate the CalculateBill class. (Prompt the user to input the number of Kilowatt Hours used and then display the total of the electric bill). The example of input/output is shown below:

Enter the number of Kilowatt Hours used: 600
Electric bill is: RM300.00
1

Expert's answer

2012-06-15T08:14:18-0400

Task

The Universe Energy electric company calculates electricity charges based upon usage. The normal rate is RM0.50 per Kilowatt Hour (KWH) for the first 1000 KWH. If the number of KWH is above 1000, then the balance from normal rate is charged for RM0.40 per KWH. Write a CalculateBill class that consists of only one method named calculate() to calculate and return the electricity charge.

Then, write one other class named DemoCalculateBill to demonstrate the CalculateBill class. (Prompt the user to input the number of Kilowatt Hours used and then display the total of the electric bill). The example of input/output is shown below:

Enter the number of Kilowatt Hours used: 600

Electric bill is: RM300.00

Solution

public class DemoCalculateBill {
    public static void main(String[] args) {
        double number;
        double bill;
        System.out.print("Enter the number of Kilowatt Hours used: ");
        Scanner in = new Scanner(System.in);
        number = Integer.parseInt(in.nextLine());
        bill = CalculateBill.calculate(number);
        System.out.println("Electric bill is: RM " + bill);
    }
}
public class CalculateBill {
    public static double calculate(double number) {
        double bill = 0;
        if (number <= 1000) {
            bill = number * 0.5;
        } else {
            bill = 500 + ((number - 1000) * 0.4);
        }
        return bill;
    }
}

Answer

Enter the number of Kilowatt Hours used: 1200

Electric bill is: RM 580

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS