1.
import java.util.Scanner;
public class SimpleEBBill {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input
System.out.print("Enter Consumer Number: ");
int no = sc.nextInt();
sc.nextLine(); // clear buffer
System.out.print("Enter Consumer Name: ");
String name = sc.nextLine();
System.out.print("Enter Previous Reading: ");
int prev = sc.nextInt();
System.out.print("Enter Current Reading: ");
int curr = sc.nextInt();
sc.nextLine(); // clear buffer
System.out.print("Enter Connection Type (domestic/commercial): ");
String type = sc.nextLine().toLowerCase();
int units = curr - prev;
double amount = 0;
// Bill Calculation
if (type.equals("domestic")) {
if (units <= 100)
amount = units * 1;
else if (units <= 200)
amount = 100 * 1 + (units - 100) * 2.5;
else if (units <= 500)
amount = 100 * 1 + 100 * 2.5 + (units - 200) * 4;
else
amount = 100 * 1 + 100 * 2.5 + 300 * 4 + (units - 500) * 6;
} else if (type.equals("commercial")) {
if (units <= 100)
amount = units * 2;
else if (units <= 200)
amount = 100 * 2 + (units - 100) * 4.5;
else if (units <= 500)
amount = 100 * 2 + 100 * 4.5 + (units - 200) * 6;
else
amount = 100 * 2 + 100 * 4.5 + 300 * 6 + (units - 500) * 7;
} else {
System.out.println("Invalid Connection Type!");
return;
}
// Output
System.out.println("\n--- Electricity Bill ---");
System.out.println("Consumer No : " + no);
System.out.println("Name : " + name);
System.out.println("Connection : " + type);
System.out.println("Units Used : " + units);
System.out.println("Total Amount : ₹" + amount);
}
}