BapBapuHa

On Time for the Exam

Jan 27th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. package com.company;
  2.  
  3.         import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Scanner scanner = new Scanner(System.in);
  10.         int examHour = Integer.parseInt(scanner.nextLine());
  11.         int examMinute = Integer.parseInt(scanner.nextLine());
  12.         int arriveHour = Integer.parseInt(scanner.nextLine());
  13.         int arriveMinute = Integer.parseInt(scanner.nextLine());
  14.         int arriveTime = arriveHour * 60 + arriveMinute;
  15.         int examTime = examHour * 60 + examMinute;
  16.         int hours = 0;
  17.         if (arriveTime > examTime) {
  18.             int minutes = arriveTime - examTime;
  19.             if (minutes >= 60) {
  20.                 hours = minutes / 60;
  21.                 minutes = minutes - 60 * hours;
  22.                 if (minutes < 10) {
  23.                     System.out.printf("Late%n%d:0%d hours after the start", hours, minutes);
  24.                 } else {
  25.                     System.out.printf("Late%n%d:%d hours after the start", hours, minutes);
  26.                 }
  27.             } else {
  28.                 System.out.printf("Late%n%d minutes after the start", minutes);
  29.             }
  30.         } else if (examTime - arriveTime <= 30) {
  31.             int minutes = examTime - arriveTime;
  32.             System.out.printf("On time%n%d minutes before the start", minutes);
  33.         } else {
  34.             int minutes = examTime - arriveTime;
  35.             if (minutes >= 60) {
  36.                 hours = minutes / 60;
  37.                 minutes = minutes - 60 * hours;
  38.                 if (minutes < 10) {
  39.                     System.out.printf("Early%n%d:0%d hours before the start", hours, minutes);
  40.                 } else {
  41.                     System.out.printf("Early%n%d:%d hours before the start", hours, minutes);
  42.                 }
  43.             } else {
  44.                 System.out.printf("Early%n%d minutes before the start", minutes);
  45.             }
  46.         }
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment