SvetlanPetrova

On Time For The Exam SoftUni

Apr 19th, 2021
642
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class OnTimeForTheExam {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int examHour = Integer.parseInt(scanner.nextLine());
  7.         int examMinutes = Integer.parseInt(scanner.nextLine());
  8.         int inHour = Integer.parseInt(scanner.nextLine());
  9.         int inMinutes = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int examTime = examHour * 60 + examMinutes;
  12.         int inTime = inHour * 60 + inMinutes;
  13.         int diffHour = 0;
  14.         int diffMinutes = 0;
  15.  
  16.         if (inTime >= (examTime - 30) && inTime <= examTime) {
  17.             if (examTime - inTime > 0) {
  18.                 diffMinutes = examTime - inTime;
  19.                 System.out.println("On time");
  20.                 System.out.printf("%d minutes before the start", diffMinutes);
  21.             }
  22.             if (examTime - inTime == 0) {
  23.                 diffMinutes = inTime - examTime;
  24.                 System.out.println("On time");
  25.             }
  26.         }
  27.  
  28.         else if (inTime < (examTime - 30)) {
  29.             if ((examTime - inTime) >= 60) {
  30.                 diffHour = (examTime - inTime) / 60;
  31.                 diffMinutes = (examTime - inTime) % 60;
  32.                 if (diffMinutes <10) {
  33.                     System.out.println("Early");
  34.                 System.out.printf("%d:0%d hours before the start", diffHour, diffMinutes);
  35.                 }
  36.                 else if (diffMinutes >=10) {
  37.                     System.out.println("Early");
  38.                     System.out.printf("%d:%d hours before the start", diffHour, diffMinutes);
  39.                 }
  40.             } else if ((examTime - inTime) < 60) {
  41.                 diffMinutes = examTime - inTime;
  42.                 System.out.println("Early");
  43.                 System.out.printf("%d minutes before the start", diffMinutes);
  44.             }
  45.         }
  46.  
  47.         else if (inTime > examTime) {
  48.             if ((inTime - examTime) >= 60) {
  49.                 diffHour = (inTime - examTime) / 60;
  50.                 diffMinutes = (inTime - examTime) % 60;
  51.                 if (diffMinutes <10) {
  52.                     System.out.println("Late");
  53.                     System.out.printf("%d:0%d hours after the start", diffHour, diffMinutes);
  54.                 }
  55.                 else if (diffMinutes >=10) {
  56.                     System.out.println("Late");
  57.                     System.out.printf("%d:%d hours after the start", diffHour, diffMinutes);
  58.                 }
  59.             }
  60.             else if ((inTime - examTime) < 60){
  61.                 diffMinutes = inTime - examTime;
  62.                 System.out.println("Late");
  63.                 System.out.printf("%d minutes after the start", diffMinutes);
  64.             }
  65.         }
  66.  
  67.     }
  68. }
  69.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×