Skip to content

Commit d9fc7b4

Browse files
committed
Basic:- Solution to calculate Electricity Bill
1 parent 7942991 commit d9fc7b4

1 file changed

Lines changed: 47 additions & 19 deletions

File tree

‎src/Scaler/Assignments/ElectricityBill.java‎

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,59 @@ public static void main(String[] args) {
88

99
int units = scanner.nextInt();
1010

11-
int billValue = 0;
11+
int bill = solve(units);
1212

13-
while (units > 0){
13+
System.out.println(bill);
1414

15-
if (units <= 50){
16-
billValue = calculateUnitRates(units);
17-
units -= 50;
18-
}else if(units > 50 && units <= 150){
15+
// int billValue = 0;
16+
//
17+
// while (units > 0){
18+
//
19+
// if (units <= 50){
20+
//// billValue = calculateUnitRates(units);
21+
// units -= 50;
22+
// }else if(units > 50 && units <= 150){
23+
//
24+
// }
25+
// }
26+
}
1927

20-
}
28+
static int solve(int A) {
29+
Double bill=0.0;
30+
if(A<=50)
31+
{
32+
bill= A*(0.50);
2133
}
22-
}
34+
else if(A<=150)
35+
{
36+
bill=50*0.50+(A-50)*0.75;
37+
}
38+
else if(A<=250)
39+
{
40+
bill=50*0.50+100*0.75+(A-150)*1.20;
2341

24-
static int calculateUnitRates(int unit){
25-
int bill = 0;
26-
if (unit > 250){
27-
bill *= 1.50;
28-
}else if(unit > 150 && unit <= 250){
29-
bill *= 1.20;
30-
}else if(unit > 50 && unit <= 150){
31-
bill *= 0.75;
32-
}else{
33-
bill *= 0.50;
3442
}
43+
else
3544

36-
return bill;
45+
{
46+
bill=50*0.50+100*0.75+100*1.20+(A-250)*1.50;
47+
}
48+
Double total = bill+0.20*bill;
49+
return ((int)Math.floor(bill+0.2*bill));
3750
}
51+
52+
// static int calculateUnitRates(int unit){
53+
// int bill = 0;
54+
// if (unit > 250){
55+
// bill *= 1.50;
56+
// }else if(unit > 150 && unit <= 250){
57+
// bill *= 1.20;
58+
// }else if(unit > 50 && unit <= 150){
59+
// bill *= 0.75;
60+
// }else{
61+
// bill *= 0.50;
62+
// }
63+
//
64+
// return bill;
65+
// }
3866
}

0 commit comments

Comments
 (0)