Advertisement
desislava_topuzakova

06. Vet Parking

Oct 23rd, 2021
840
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class VetParking_06 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int days = Integer.parseInt(scanner.nextLine());
  7.         int hoursPerDay = Integer.parseInt(scanner.nextLine());
  8.         //обходим всички дни -> първия до последния
  9.         double sumAllDays = 0;//сумата от всички дни
  10.         for (int day = 1; day <= days; day++) {
  11.             //обходя всички часове
  12.             double sumPerDay = 0; //сумата за всеки един ден
  13.             for (int hour = 1; hour <= hoursPerDay; hour++) {
  14.                 //цена на час
  15.                 //четен ден и нечетен час -> 2.50
  16.                 if (day % 2 == 0 && hour % 2 == 1) {
  17.                     sumPerDay += 2.50;
  18.                 }
  19.                 //нечетен ден и четен час -> 1.25
  20.                 else if (day % 2 == 1 && hour % 2 == 0) {
  21.                     sumPerDay += 1.25;
  22.                 }
  23.                 //четен ден и четен час или нечетен ден и нечетен час -> 1
  24.                 else {
  25.                     sumPerDay += 1;
  26.                 }
  27.             }
  28.             sumAllDays += sumPerDay;
  29.             System.out.printf("Day: %d - %.2f leva%n", day, sumPerDay);
  30.         }
  31.         System.out.printf("Total: %.2f leva", sumAllDays);
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement