AsyaDamyanova

On Time For The Exam

Oct 31st, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 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.         int examHour = Integer.parseInt(scanner.nextLine());
  7.         int examMin = Integer.parseInt(scanner.nextLine());
  8.         int arriveHour = Integer.parseInt(scanner.nextLine());
  9.         int arriveMin = Integer.parseInt(scanner.nextLine());
  10.  
  11.         int differenceTotalMin = (arriveHour * 60 + arriveMin) - (examHour * 60 + examMin);
  12.         int differenceHours = Math.abs(differenceTotalMin / 60);
  13.         int differenceMin = Math.abs(differenceTotalMin % 60);
  14.  
  15.         if (differenceTotalMin > 0) {
  16.             System.out.println("Late");
  17.  
  18.         } else if (differenceTotalMin >= -30) {
  19.             System.out.println("On time");
  20.  
  21.         } else {
  22.             System.out.println("Early");
  23.  
  24.         }
  25.         if (differenceTotalMin >= 60) {
  26.             System.out.printf("%d:%02d hours after the start", differenceHours, differenceMin);
  27.  
  28.         } else if (differenceTotalMin > 0) {
  29.             System.out.printf("%d minutes after the start", differenceMin);
  30.  
  31.         }
  32.         if (differenceTotalMin <= -60) {
  33.             System.out.printf("%d:%02d hours before the start", differenceHours, differenceMin);
  34.  
  35.         } else if (differenceTotalMin < 0) {
  36.             System.out.printf("%d minutes before the start", differenceMin);
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment