vpaleshnikov

Bills

Apr 13th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Problem04_Bills {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int months = Integer.parseInt(scanner.nextLine());
  8.         double electricity = 0.0;
  9.         double water = 20.0;
  10.         double internet = 15.0;
  11.         double others = 0.0;
  12.         double others2 = 0.0;
  13.  
  14.         for (int i = 0; i < months; i++) {
  15.             double electricityBill = Double.parseDouble(scanner.nextLine());
  16.             others = ((electricityBill + water + internet) * 0.2) + (electricityBill + water + internet);
  17.             others2 = others + others2;
  18.             electricity = electricity + electricityBill;
  19.         }
  20.         double waterBill = months * water;
  21.         double internetBill = months * internet;
  22.         double monthlyBill = (electricity + waterBill + internetBill + others2)/months;
  23.  
  24.         System.out.printf("Electricity: %.2f lv%n",electricity);
  25.         System.out.printf("Water: %.2f lv%n",waterBill);
  26.         System.out.printf("Internet: %.2f lv%n",internetBill);
  27.         System.out.printf("Other: %.2f lv%n",others2);
  28.         System.out.printf("Average: %.2f lv%n",monthlyBill);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment