Advertisement
marking2112

OnTimeForExam

Oct 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OnTimeForExam {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int hourOfExam = Integer.parseInt(scanner.nextLine());
  8.         int minutesOfExam = Integer.parseInt(scanner.nextLine());
  9.         int hourOfArrive = Integer.parseInt(scanner.nextLine());
  10.         int minutesOfArrive = Integer.parseInt(scanner.nextLine());
  11.  
  12.         int timeOfExam = (hourOfExam * 60) + minutesOfExam;
  13.         int timeOfArrive = (hourOfArrive * 60) + minutesOfArrive;
  14.  
  15.  
  16.         if (timeOfArrive > timeOfExam) {
  17.             int timeLate = timeOfArrive - timeOfExam;
  18.  
  19.             if (timeLate >= 60) {
  20.                 int lateHours = timeLate / 60;
  21.                 int lateMins = timeLate % 60;
  22.                 System.out.println("Late");
  23.                 System.out.printf("%d:%02d hours after the start", lateHours, lateMins);
  24.             } else {
  25.                 System.out.println("Late");
  26.                 System.out.printf("%d minutes after the start", timeLate);
  27.             }
  28.         } else if (timeOfArrive < timeOfExam) {
  29.             int timeEarly = timeOfExam - timeOfArrive;
  30.  
  31.             if (timeEarly > 30 && timeEarly < 60) {
  32.                 int earlyHours = timeEarly /60;
  33.                 int earlyMins = timeEarly % 60;
  34.                 System.out.println("Early");
  35.                 System.out.printf("%02d minutes before the start", earlyMins);
  36.             } else if (timeEarly > 30 && timeEarly >= 60) {
  37.                 int earlyHours = timeEarly /60;
  38.                 int earlyMins = timeEarly % 60;
  39.                 System.out.println("Early");
  40.                 System.out.printf("%d:%02d hours before the start", earlyHours, earlyMins);
  41.             } else {
  42.                 System.out.println("On time");
  43.                 System.out.printf("%d minutes before the start", timeEarly);
  44.             }
  45.          } else {
  46.             System.out.println("On time");
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement