KenDoBG

On Time For Exam

Mar 17th, 2021
129
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.  
  7.         int examHour = Integer.parseInt(scanner.nextLine());
  8.         int examMinutes = Integer.parseInt(scanner.nextLine());
  9.         int arrivalHours = Integer.parseInt(scanner.nextLine());
  10.         int arrivalMinutes = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int arrivalTime = arrivalHours * 60 + arrivalMinutes;
  13.         int examTime = examHour * 60 + examMinutes;
  14.  
  15.         int difference = Math.abs(arrivalTime-examTime);
  16.         int differenceHours = difference/60;
  17.         int differenceMinutes = difference%60;
  18.  
  19.         if (arrivalTime-examTime >= 60) {
  20.                 System.out.printf("Late%n%d:%02d hours after the start", differenceHours, differenceMinutes);
  21.         }
  22.         else if (arrivalTime-examTime >0){
  23.             System.out.printf("Late%n%d minutes after the start",differenceMinutes);
  24.         }
  25.         else if (examTime-arrivalTime >= 60) {
  26.                 System.out.printf("Early%n%d:%02d hours before the start", differenceHours, differenceMinutes);
  27.             }
  28.  
  29.         else if (examTime-arrivalTime > 30){
  30.             System.out.printf("Early%n%d minutes before the start",differenceMinutes);
  31.         }
  32.         else
  33.             System.out.printf("On time%n%d minutes before the start",differenceMinutes);
  34.         }
  35.     }
  36.  
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment