Advertisement
CR7CR7

OnTimeForTheExam

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