Angel_Kalinkov

PBE-Coding101Exam-6March2016-OnTimeForTheExam_AngelKalinkov

Feb 2nd, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 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 arriveHour = Integer.parseInt(scanner.nextLine());
  10.         int arriveMinutes = Integer.parseInt(scanner.nextLine());
  11.  
  12.         String late = "Late";
  13.         String onTime = "On time";
  14.         String early = "Early";
  15.         int examTimeToMin = examHour * 60 + examMinutes;
  16.         int arriveTimeToMin = arriveHour * 60 + arriveMinutes;
  17.         int difference = arriveTimeToMin - examTimeToMin;
  18.  
  19.         String studentArrival = late;
  20.         if (difference < -30) {
  21.             studentArrival = early;
  22.         } else if (difference <= 0) {
  23.             studentArrival = onTime;
  24.         }
  25.         String result = "";
  26.         if (difference != 0) {
  27.             int hoursDifference = Math.abs(difference / 60);
  28.             int minutesDifference = Math.abs(difference % 60);
  29.             if (hoursDifference > 0) {
  30.                 result = String.format("%d:%02d hours", hoursDifference, minutesDifference);
  31.             } else {
  32.                 result = minutesDifference + " minutes";
  33.             }
  34.             if (difference < 0) {
  35.                 result += " before the start";
  36.             } else {
  37.                 result += " after the start";
  38.             }
  39.         }
  40.         System.out.println(studentArrival);
  41.         if (!result.isEmpty()) {
  42.             System.out.println(result);
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment