Advertisement
Deiancom

On Time for the Exam

Feb 1st, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 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.         int examHour = Integer.parseInt(scanner.nextLine());
  7.         int examMinute = Integer.parseInt(scanner.nextLine());
  8.         int arrivalHour = Integer.parseInt(scanner.nextLine());
  9.         int arrivalMinute = Integer.parseInt(scanner.nextLine());
  10.         examMinute += examHour * 60;
  11.         arrivalMinute += arrivalHour * 60;
  12.         int difference = examMinute - arrivalMinute;
  13.         if (difference < 0) {
  14.             System.out.println("Late");
  15.             if (Math.abs(difference) < 60) {
  16.                 System.out.printf("%d minutes after the start",Math.abs(difference));
  17.             }else {
  18.                 System.out.printf("%d:%02d hours after the start",Math.abs(difference / 60),Math.abs(difference % 60));
  19.             }
  20.         }else if (difference > 0) {
  21.             if (difference <= 30) {
  22.                 System.out.println("On time");
  23.             }else {
  24.                 System.out.println("Early");
  25.             }
  26.             if (difference < 60) {
  27.                 System.out.printf("%d minutes before the start",difference);
  28.             }else {
  29.                 System.out.printf("%d:%02d hours before the start",difference / 60,difference % 60);
  30.             }
  31.         }else {
  32.             System.out.println("On time");
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement