Lyubohd

09. On Time for the Exam

Apr 5th, 2020
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class LiveDemo {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         int hourOfExam = Integer.parseInt(scan.nextLine());
  8.         int minutesOfExam = Integer.parseInt(scan.nextLine());
  9.         int hoursOfArriving = Integer.parseInt(scan.nextLine());
  10.         int minutesOfArriving = Integer.parseInt(scan.nextLine());
  11.  
  12.         int totalMinutesOfExam = hourOfExam * 60 + minutesOfExam;
  13.         int totalMinutesOfArriving = hoursOfArriving * 60 + minutesOfArriving;
  14.  
  15.         if (totalMinutesOfArriving > totalMinutesOfExam) {
  16.             System.out.println("Late");
  17.             int timeLate = totalMinutesOfArriving - totalMinutesOfExam;
  18.             if (timeLate < 60) {
  19.                 System.out.printf("%d minutes after the start", timeLate);
  20.             } else {
  21.                 int hours = timeLate / 60;
  22.                 int minutes = timeLate % 60;
  23.                 if (minutes < 10) {
  24.                     System.out.printf("%d:0%d hours after the start", hours, minutes);
  25.                 } else {
  26.                     System.out.printf("%d:%d hours after the start", hours, minutes);
  27.                 }
  28.             }          // 80      60     == 20
  29.         } else if (totalMinutesOfExam - totalMinutesOfArriving <= 30) {
  30.             System.out.println("On time");
  31.             int early = totalMinutesOfExam - totalMinutesOfArriving;
  32.             if (early != 0) {
  33.                 System.out.printf("%d minutes before the start", early);
  34.             }
  35.         } else if (totalMinutesOfExam - totalMinutesOfArriving > 30) {
  36.             System.out.println("Early");
  37.             int earlyMinutes = totalMinutesOfExam - totalMinutesOfArriving;
  38.             int hours = earlyMinutes / 60;
  39.             int minutes = earlyMinutes % 60;
  40.  
  41.             if (earlyMinutes < 60) {
  42.                 System.out.printf("%d minutes before the start", minutes);
  43.             } else {
  44.                 if (minutes < 10) {
  45.                     System.out.printf("%d:0%d hours before the start", hours, minutes);
  46.                 } else {
  47.                     System.out.printf("%d:%d hours before the start", hours, minutes);
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment