Advertisement
myrdok123

08. On Time for the Exam

Jan 21st, 2024 (edited)
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package W03ConditionalStatementsAdvanced.Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08OnTimeForTheExam {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int examHour = Integer.parseInt(scanner.nextLine());
  11.         int examMinutes = Integer.parseInt(scanner.nextLine());
  12.         int arrivalHour = Integer.parseInt(scanner.nextLine());
  13.         int arrivalMinutes = Integer.parseInt(scanner.nextLine());
  14.  
  15.         //Превръщаме всичко във минути
  16.         int examTotalMinutes = examHour * 60 + examMinutes;
  17.         int arrivalTotalMinutes = arrivalHour * 60 + arrivalMinutes;
  18.  
  19.         //създаваме променлива, в която ще пазим минутите разлика
  20.         int diff = Math.abs(examTotalMinutes - arrivalTotalMinutes);
  21.  
  22.         //Проверяваме дали общите минути на пристига са по-големи от общите минути на изпита
  23.         if(arrivalTotalMinutes > examTotalMinutes){
  24.             //Принтираме, че е закъснял
  25.             System.out.println("Late");
  26.  
  27.             //Проверяваме дали закъснението е по-малко или повече от 60 мин.
  28.             if(diff < 60){
  29.                 System.out.printf("%d minutes after the start", diff);
  30.             }else {
  31.                 int hour = diff / 60;
  32.                 int minutes = diff % 60;
  33.                 System.out.printf("%d:%02d hours after the start", hour, minutes);
  34.             }
  35.  
  36.         } else if (diff <= 30) {
  37.  
  38.             System.out.println("On time");
  39.             if (examTotalMinutes != arrivalTotalMinutes){
  40.                 System.out.printf("%d minutes before the start", diff);
  41.             }
  42.  
  43.         } else {
  44.             System.out.println("Early");
  45.             int hour = diff / 60;
  46.             int minutes = diff % 60;
  47.  
  48.             if(diff < 60){
  49.                 System.out.printf("%d minutes before the start", minutes);
  50.             }else {
  51.                 System.out.printf("%d:%02d hours before the start", hour, minutes);
  52.             }
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement