Advertisement
MladenKarachanov

OnTimeForTheExam

Jul 16th, 2023
1,181
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 1 0
  1. package ProgrammingBasics2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class OnTimefortheExam {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int hoursExam = Integer.parseInt(scanner.nextLine());
  9.         int minutesExam = Integer.parseInt(scanner.nextLine());
  10.         int hourOfArrival = Integer.parseInt(scanner.nextLine());
  11.         int minuteOfArrival = Integer.parseInt(scanner.nextLine());
  12.         int examTotalMinutes = hoursExam * 60 + minutesExam;
  13.         int arrivalTotalMinutes = hourOfArrival * 60 + minuteOfArrival;
  14.  
  15.         int diff = Math.abs(examTotalMinutes - arrivalTotalMinutes);
  16.         if (arrivalTotalMinutes > examTotalMinutes) {
  17.             System.out.println("Late");
  18.             if (diff < 60) {
  19.                 System.out.printf("%d minutes after the start", diff);
  20.             } else {
  21.                 int hours = diff / 60;
  22.                 int minutes = diff % 60;
  23.                 System.out.printf("%d:%02d hours after the start", hours, minutes);
  24.             }
  25.         }else if (diff <=30) {
  26.             System.out.println("On time");
  27.             if (examTotalMinutes != arrivalTotalMinutes) {
  28.                 System.out.printf("%d minutes before the start", diff);
  29.             }
  30.         }else{
  31.             System.out.println("Early");
  32.             if (diff < 60) {
  33.                 System.out.printf("%d minutes before the start", diff);
  34.             }else{
  35.                 int hours =diff / 60;
  36.                 int minutes = diff %60;
  37.                 System.out.printf("%d: %02d hours before the start",hours,minutes);
  38.  
  39.  
  40.  
  41.  
  42.                     }
  43.                 }
  44.             }
  45.  
  46.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement