myrdok123

08. On Time for the Exam

May 14th, 2023
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. package L03_ConditionalStatementsAdvanced;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08_OnTimeForTheExam {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  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.         int diffMinutes = Math.abs(examTotalMinutes - arrivalTotalMinutes);
  20.  
  21.         //правим проверка дали е закъснял
  22.         if(arrivalTotalMinutes > examTotalMinutes){
  23.             System.out.println("Late");
  24.             //Ако разликата в минутите на пристига и минутите на изпита е по-малка от 60 -> принтираме минути
  25.             //Ако разликата е по-голяма трябва да принтираме час:минути
  26.  
  27.             if(diffMinutes < 60){
  28.                 System.out.printf("%d minutes after the start", diffMinutes);
  29.             }else {
  30.  
  31.                 int hour = diffMinutes / 60;
  32.                 int minute = diffMinutes % 60;
  33.                 System.out.printf("%d:%02d hours after the start", hour, minute);
  34.             }
  35.  
  36.         }else  if( diffMinutes <= 30){
  37.             System.out.println("On time");
  38.  
  39.             if (diffMinutes != 0){
  40.                 System.out.printf("%d minutes before the start", diffMinutes);
  41.             }
  42.  
  43.         }else {
  44.             System.out.println("Early");
  45.             if (diffMinutes < 60){
  46.                 System.out.printf("%d minutes before the start", diffMinutes);
  47.             }else {
  48.  
  49.                 int hour = diffMinutes / 60;
  50.                 int minute = diffMinutes % 60;
  51.                 System.out.printf("%d:%02d hours before the start", hour, minute);
  52.  
  53.  
  54.             }
  55.  
  56.         }
  57.  
  58.  
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment