forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectricitybill.java
More file actions
26 lines (26 loc) · 874 Bytes
/
Electricitybill.java
File metadata and controls
26 lines (26 loc) · 874 Bytes
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
class ElectricityBillExample1
{
// main() method start
public static void main(String args[])
{
// declare and initialize variable units
int units = 380;
// variable to calculate electricity bill to pay
double billToPay = 0;
// check whether units are less than 100
if(units < 100)
{
billToPay = units * 1.20;
}
// check whether the units are less than 300
else if(units < 300){
billToPay = 100 * 1.20 + (units - 100) * 2;
}
// check whether the units are greater than 300
else if(units > 300)
{
billToPay = 100 * 1.20 + 200 * 2 + (units - 300) * 3;
}
System.out.println("The electricity bill for " +units+ " is : " + billToPay);
}
}