-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain21.java
More file actions
51 lines (41 loc) · 1.63 KB
/
Main21.java
File metadata and controls
51 lines (41 loc) · 1.63 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
50
51
package ifelsejava;
import java.util.Scanner;
public class Main21 {
public static void main(String[] args) {
/*
Calculate total electricity bill according to the given condition:
For first 50 units Tk. 1.50/unit
For next 100 units Tk. 2.25/unit
For next 100 units Tk. 3.00/unit
For unit above 250 Tk. 3.75/unit
An additional surcharge of 20% is added to the bill
*/
double unit, surcharge, taka = 0;
Scanner input = new Scanner(System.in);
System.out.println("Input electricity unit charges and calculate total electricity bill.\n");
System.out.print("Enter unit: ");
unit = input.nextDouble();
if (unit >= 1 && unit <= 50) {
//For first 50 units Tk. 1.50/unit
taka = unit * 1.5;
surcharge = taka * 0.2; //Surcharge 20%
taka = taka + surcharge;
} else if (unit >= 51 && unit <= 100) {
//For next 100 units Tk. 2.25/unit
taka = unit * 2.25;
surcharge = taka * 0.2; //Surcharge 20%
taka = taka + surcharge;
} else if (unit >= 101 && unit <= 250) {
//For next 100 units Tk. 3.00/unit
taka = unit * 3.0;
surcharge = taka * 0.2; //Surcharge 20%
taka = taka + surcharge;
} else if (unit >= 251) {
//For unit above 250 Tk. 3.75/unit
taka = unit * 3.75;
surcharge = taka * 0.2; //Surcharge 20%
taka = taka + surcharge;
}
System.out.println("Total cost: " + taka);
}
}