Advertisement
Guest User

Untitled

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