0% found this document useful (0 votes)
58 views3 pages

Q002 Calculate Electricity Bill - Program in Java

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views3 pages

Q002 Calculate Electricity Bill - Program in Java

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q002_Electricity_Bill_Generation

import java.util.Scanner;

public class ElectricityBill {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Calculate Electricity Bill");

System.out.print("Enter Customer ID: ");

int customerId = sc.nextInt();

sc.nextLine();

System.out.print("Enter the name of the customer: ");

String customerName = sc.nextLine();

System.out.print("Enter the unit consumed by the customer: ");

int unitsConsumed = sc.nextInt();

float amount = calcAmount(unitsConsumed);

float surcharge = calcSurcharge(amount);

float netAmount = amount + surcharge;

if (netAmount < 100) {

netAmount = 100;

System.out.println("\nElectricity Bill");

System.out.println("Customer ID :" + customerId);

System.out.println("Customer Name :" + customerName);

System.out.println("Unit Consumed :" + unitsConsumed);

System.out.println("Amount Charges @Rs. " + getUnitRate(unitsConsumed) + " per unit :" +


amount);

System.out.println("Surcharge Amount :" + surcharge);


System.out.println("Net Amount to be paid :" + netAmount);

sc.close();

public static float calcAmount(int units) {

float amount;

if (units <= 199) {

amount = units * 1.20f;

} else if (units >= 200 && units < 400) {

amount = units * 1.50f;

} else if (units >= 400 && units < 600) {

amount = units * 1.80f;

} else {

amount = units * 2.00f;

return amount;

public static float calcSurcharge(float amount) {

if (amount > 400) {

return amount * 0.15f;

return 0;

public static float getUnitRate(int units) {

if (units <= 199) {

return 1.20f;

} else if (units >= 200 && units < 400) {

return 1.50f;
} else if (units >= 400 && units < 600) {

return 1.80f;

} else {

return 2.00f;

Output:
Calculate Electricity Bill
Enter Customer ID: 1001
Enter the name of the customer: Sana
Enter the unit consumed by the customer: 800

Electricity Bill
Customer ID :1001
Customer Name :Sana
Unit Consumed :800
Amount Charges @Rs. 2 per unit :1600
Surcharge Amount :240
Net Amount to be paid :1840

You might also like