TZinovieva

Bills 100/100

Apr 14th, 2022 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package PBMoreExercisesForLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Bills {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int months = Integer.parseInt(scanner.nextLine());
  10.         double totalElectricity = 0;
  11.         double water = 20;
  12.         double internet = 15;
  13.         double allOthers = 0;
  14.  
  15.         for (int i = 1; i <= months ; i++) {
  16.             double electricity = Double.parseDouble(scanner.nextLine());
  17.  
  18.             totalElectricity = totalElectricity + electricity;
  19.             double others = (electricity + water + internet) + (electricity + water + internet) * 20 / 100;
  20.             allOthers = allOthers + others;
  21.  
  22.         }
  23.         water = water * months;
  24.         internet = internet * months;
  25.  
  26.         double costs = totalElectricity + water + internet + allOthers;
  27.         double averageCosts = costs / months;
  28.  
  29.         System.out.printf("Electricity: %.2f lv%n", totalElectricity);
  30.         System.out.printf("Water: %.2f lv%n", water);
  31.         System.out.printf("Internet: %.2f lv%n", internet);
  32.         System.out.printf("Other: %.2f lv%n", allOthers);
  33.         System.out.printf("Average: %.2f lv", averageCosts);
  34.     }
  35. }
Add Comment
Please, Sign In to add comment