Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

import java.util.

Scanner;

public class ElectricityBillCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Capture customer details

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

String customerName = scanner.nextLine();

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

String customerId = scanner.nextLine();

System.out.print("Enter previous meter reading: ");

int previousReading = scanner.nextInt();

System.out.print("Enter current meter reading: ");

int currentReading = scanner.nextInt();

// Calculate bill

int unitsConsumed = currentReading - previousReading;

double billAmount = calculateBill(unitsConsumed);

// Display bill

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

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

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

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

System.out.println("Bill Amount: $" + billAmount);

scanner.close();
}

// Calculate bill based on units consumed

public static double calculateBill(int unitsConsumed) {

double billAmount = 0.0;

// Customize the billing logic according to your requirements

// Here's a simple example: $0.10 per unit

billAmount = unitsConsumed * 0.10;

return billAmount;

You might also like