Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Bills {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int monthNo = scanner.nextInt();
- int costWater = 20, costInternet = 15;
- double totalCostElectricity = 0;
- for (int i = 1; i <= monthNo; i++) {
- double costsElectricity = scanner.nextDouble();
- totalCostElectricity += costsElectricity;
- }
- double totalCostWater = costWater * monthNo;
- double totalCostInternet = costInternet * monthNo;
- double totalCostOthers = (totalCostElectricity + totalCostWater + totalCostInternet) * 1.2;
- double average = (totalCostElectricity + totalCostWater + totalCostInternet + totalCostOthers) / monthNo;
- System.out.printf("Electricity: %.2f $\n",totalCostElectricity);
- System.out.printf("Water: %.2f $\n", totalCostWater);
- System.out.printf("Internet: %.2f $\n", totalCostInternet);
- System.out.printf("Other: %.2f $\n", totalCostOthers);
- System.out.printf("Average: %.2f $ \n", average);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement