Advertisement
ivanmitkoff

Untitled

Jun 9th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  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.  
  7.         int examHour = Integer.parseInt(scanner.nextLine());
  8.         int examMinutes = Integer.parseInt(scanner.nextLine());
  9.         int arrivalHour = Integer.parseInt(scanner.nextLine());
  10.         int arrivalMinutes = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int examTimeInMins = (examHour * 60) + examMinutes;
  13.         int arrivalTimeInMins = (arrivalHour * 60) + arrivalMinutes;
  14.  
  15.         int diff = examTimeInMins - arrivalTimeInMins;
  16.         int hour = Math.abs(diff / 60);
  17.         int mins = Math.abs(diff % 60);
  18.  
  19.         if (diff < 0) {
  20.             System.out.println("Late");
  21.             if (Math.abs(diff) >= 60) {
  22.                 if (mins < 10) {
  23.                     System.out.printf("%d:%0d hours after the start", hour, mins);
  24.                 } else {
  25.                     System.out.printf("%d:%d hours after the start", hour, mins);
  26.                 }
  27.             } else {
  28.                 System.out.printf("%d minutes after the start", mins);
  29.             }
  30.         } else if (diff >= 0 && diff <= 30) {
  31.             if (diff == 0) {
  32.                 System.out.println("On time");
  33.             } else {
  34.                 System.out.println("On time");
  35.                 System.out.printf("%d minutes before the start", mins);
  36.             }
  37.         } else {
  38.             System.out.println("Early");
  39.             if (Math.abs(diff) >= 60) {
  40.                 if (mins < 10) {
  41.                     System.out.printf("%d:%0d hours before the start", hour, mins);
  42.                 } else {
  43.                     System.out.printf("%d:%d hours before the start", hour, mins);
  44.                 }
  45.             } else {
  46.                 System.out.printf("%d minutes before the start", mins);
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement