Advertisement
Lyubohd

Untitled

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