Advertisement
nevenailievaa

11. HappyCat Parking

Mar 6th, 2024
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P11HappyCatParking {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int numberOfDays = Integer.parseInt(scanner.nextLine());
  8.         int numberOfHours = Integer.parseInt(scanner.nextLine());
  9.         double price = 0;
  10.  
  11.         for (int days = 1; days <= numberOfDays; days++) {
  12.             double pricePerDay = 0;
  13.             boolean dayIsEven = days % 2 == 0;
  14.  
  15.             for (int hours = 1; hours <= numberOfHours; hours++) {
  16.                 boolean hourIsEven = hours % 2 == 0;
  17.                 if (dayIsEven && !hourIsEven) {
  18.                     pricePerDay = pricePerDay + 2.5;
  19.                 } else if (!dayIsEven && hourIsEven) {
  20.                     pricePerDay = pricePerDay + 1.25;
  21.                 } else {
  22.                     pricePerDay = pricePerDay + 1.0;
  23.                 }
  24.             }
  25.             System.out.printf("Day: %d - %.2f leva%n", days, pricePerDay);
  26.             price = price + pricePerDay;
  27.         }
  28.         System.out.printf("Total: %.2f leva", price);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement