-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBills.java
More file actions
40 lines (30 loc) · 1.25 KB
/
Copy pathBills.java
File metadata and controls
40 lines (30 loc) · 1.25 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
package ForLoop;
import java.util.Scanner;
public class Bills {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int months = Integer.parseInt(scanner.nextLine());
double averageBill = 0;
int waterBill = 20;
int netBill = 15;
double anotherBill = 0;
double totalElectricity = 0;
double totalWater = 0;
double totalNet = 0;
double totalAnother = 0;
for (int i = 1; i <= months ; i++) {
double billElectricity = Double.parseDouble(scanner.nextLine());
totalElectricity += billElectricity;
totalWater += 20;
totalNet += 15;
anotherBill = billElectricity + waterBill + netBill + ((billElectricity + waterBill + netBill) * 0.20);
totalAnother += anotherBill;
}
averageBill = (totalElectricity + totalWater + totalNet + totalAnother) / months;
System.out.printf("Electricity: %.2f lv%n",totalElectricity);
System.out.printf("Water: %.2f lv%n",totalWater);
System.out.printf("Internet: %.2f lv%n",totalNet);
System.out.printf("Other: %.2f lv%n",totalAnother);
System.out.printf("Average: %.2f lv",averageBill);
}
}