Advertisement
Spocoman

06. Bills

Aug 28th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Bills {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int months = Integer.parseInt(scanner.nextLine());
  7.         double electricity = 0, water = 20.00, internet = 15.00, other = 0;
  8.  
  9.         for (int i = 0; i < months; i++) {
  10.             double currentBill = Double.parseDouble(scanner.nextLine());
  11.             electricity += currentBill;
  12.             other += (currentBill + water + internet) * 1.2;
  13.         }
  14.         double average = (electricity + other) / months + water + internet;
  15.  
  16.         System.out.printf("Electricity: %.2f lv\n", electricity);
  17.         System.out.printf("Water: %.2f lv\n", water * months);
  18.         System.out.printf("Internet: %.2f lv\n", internet * months);
  19.         System.out.printf("Other: %.2f lv\n", other);
  20.         System.out.printf("Average: %.2f lv\n", average);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement