The Karnataka Electricity Board Charges as follows: Units consumed Charges Up to 100 units Rs 4.80/unit For next 200 units Rs 5.50/unit For next 300 units Rs 6.80/unit More than 600 units Rs 7.50/unit Write a program to input consumer’s name, consumer number and the units consumed. The program displays the following information at the time of receiving the money. Karnataka Electricity Board Receipt Consumer Number: Consumer’s Name: Units Consumed: Monthly Amount:
Answers
Answer:
import java.util.Scanner;
public class KboatElectricBill
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Consumer Name: ");
String name = in.nextLine();
System.out.print("Enter Unit's Consumed: ");
int units = in.nextInt();
double amt = 0.0;
if (units <= 200)
amt = units * 3.8;
else if (units <= 300)
amt = (200 * 3.8) + ((units - 200) * 4.4);
else if (units <= 400)
amt = (200 * 3.8) + (100 * 4.4) + ((units - 300) * 5.1);
else
amt = (200 * 3.8) + (100 * 4.4) + (100 * 5.1) + ((units - 400) * 5.8);
System.out.println("Consumer Name: " + name);
System.out.println("Units Consumed: " + units);
System.out.println("Bill Amount: " + amt);
}
}
OUTPUT