Advertisement
borkins

Exam 06-Mar-2016 - 03. On Time for the Exam

May 14th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. /**
  2.  * Project: Exam_06_March_2016 - created by borkins on 2017-05-14.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _03_OnTimeForTheExam
  8. {
  9.     public static void main(String[] args)
  10.     {
  11.         Scanner console = new Scanner(System.in);
  12.    
  13.         int examHrs = Integer.parseInt(console.nextLine());
  14.         int examMin = Integer.parseInt(console.nextLine());
  15.         int arriveHrs = Integer.parseInt(console.nextLine());
  16.         int arriveMin = Integer.parseInt(console.nextLine());
  17.    
  18.         int diffTotalMin = (arriveHrs * 60 + arriveMin) - (examHrs * 60 + examMin);
  19.         int diffHrs = Math.abs(diffTotalMin / 60);
  20.         int diffMin = Math.abs(diffTotalMin % 60);
  21.    
  22.         if (diffTotalMin > 0) {
  23.             System.out.println("Late");
  24.         }
  25.         else if (diffTotalMin >= -30) {
  26.             System.out.println("On time");
  27.         }
  28.         else {
  29.             System.out.println("Early");
  30.         }
  31.    
  32.         if (diffTotalMin >= 60) {
  33.             System.out.printf("%d:%02d hours after the start", diffHrs, diffMin);
  34.         }
  35.         else if (diffTotalMin > 0) {
  36.             System.out.printf("%d minutes after the start", diffMin);
  37.         }
  38.    
  39.         if (diffTotalMin <= -60) {
  40.             System.out.printf("%d:%02d hours before the start", diffHrs, diffMin);
  41.         }
  42.         else if (diffTotalMin < 0) {
  43.             System.out.printf("%d minutes before the start", diffMin);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement