Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Bills {
  3. public static void main(String[] args) {
  4. Scanner scanner = new Scanner(System.in);
  5. int monthNo = scanner.nextInt();
  6. int costWater = 20, costInternet = 15;
  7. double totalCostElectricity = 0;
  8. for (int i = 1; i <= monthNo; i++) {
  9. double costsElectricity = scanner.nextDouble();
  10. totalCostElectricity += costsElectricity;
  11. }
  12. double totalCostWater = costWater * monthNo;
  13. double totalCostInternet = costInternet * monthNo;
  14. double totalCostOthers = (totalCostElectricity + totalCostWater + totalCostInternet) * 1.2;
  15. double average = (totalCostElectricity + totalCostWater + totalCostInternet + totalCostOthers) / monthNo;
  16. System.out.printf("Electricity: %.2f $\n",totalCostElectricity);
  17. System.out.printf("Water: %.2f $\n", totalCostWater);
  18. System.out.printf("Internet: %.2f $\n", totalCostInternet);
  19. System.out.printf("Other: %.2f $\n", totalCostOthers);
  20. System.out.printf("Average: %.2f $ \n", average);
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement