tchenkov

L04u14_OnTimeForTheExam

Jan 23rd, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package Uprajneniq;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by todor on 24.01.2017 г..
  7.  */
  8. public class u14_OnTimeForTheExam {
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scan = new Scanner(System.in);
  12.  
  13.         int examHours = Integer.parseInt(scan.nextLine());
  14.         int examMinutes = Integer.parseInt(scan.nextLine());
  15.         int arrivalHours = Integer.parseInt(scan.nextLine());
  16.         int arrivalMinutes = Integer.parseInt(scan.nextLine());
  17.  
  18.         int examHoursToMin = (examHours * 60) + examMinutes;
  19.         int arrivalHoursToMin = (arrivalHours * 60) + arrivalMinutes;
  20.         int minDifference = arrivalHoursToMin - examHoursToMin;
  21.  
  22.         if (minDifference > 0){
  23.             int hours = minDifference/60;
  24.             int minutes = minDifference%60;
  25.             if (hours > 0)
  26.                 System.out.printf("Late %d:%02d hours after the start", hours, minutes);
  27.             else
  28.                 System.out.printf("Late %d minutes after the start", minutes);
  29.         }
  30.         else if (minDifference < -30){
  31.             int hours = Math.abs(minDifference)/60;
  32.             int minutes = Math.abs(minDifference)%60;
  33.             if (hours > 0)
  34.                 System.out.printf("Early %d:%02d hours before the start", hours, minutes);
  35.             else
  36.                 System.out.printf("Early %d minutes before the start", minutes);
  37.         }
  38.         else {
  39.             int minutes = Math.abs(minDifference);
  40.             if (minDifference == 0)
  41.                 System.out.println("On time");
  42.             else
  43.                 System.out.printf("On time %d minutes before the start", minutes);
  44.         }
  45.  
  46.     }
  47. }
Add Comment
Please, Sign In to add comment