-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectricityBill.java
More file actions
49 lines (37 loc) · 1.32 KB
/
Copy pathElectricityBill.java
File metadata and controls
49 lines (37 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class ElectricityBill{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String customerName;
int units;
double billAmount = 0;
double tax;
double finalBill;
System.out.print("Enter Customer Name: ");
customerName = sc.nextLine();
System.out.print("Enter Units Consumed: ");
units = sc.nextInt();
// Bill Calculation
if (units <= 100) {
billAmount = units * 2;
}
else if (units <= 200) {
billAmount = (100 * 2) + ((units - 100) * 3);
}
else {
billAmount = (100 * 2) + (100 * 3) + (100 * 5) + ((units - 300) * 7);
}
// Tax Calculation (5%)
tax = billAmount * 0.05;
// Final Bill
finalBill = billAmount + tax;
// Output
System.out.println("\n------ Electricity Bill ------");
System.out.println("Customer Name : " + customerName);
System.out.println("Units Consumed: " + units);
System.out.println("Bill Amount : Rs." + billAmount);
System.out.println("Tax (5%) : Rs." + tax);
System.out.println("Final Bill : Rs." + finalBill);
sc.close();
}
}