Advertisement
myrdok123

P08OnTimeForTheExam

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