silviasj

on time for the exam2

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