Advertisement
peterbodlev

On Time for The Exam

May 17th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class primeri {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner (System.in);
  6.         int hourOfExam = Integer.parseInt(scanner.nextLine());
  7.         int minuteOfExam = Integer.parseInt(scanner.nextLine());
  8.         int hourOfArrival = Integer.parseInt(scanner.nextLine());
  9.         int minuteOfArrival = Integer.parseInt(scanner.nextLine());
  10.  
  11.         if (hourOfExam == hourOfArrival && minuteOfExam == minuteOfArrival){
  12.             System.out.println("On time");
  13.         }else if (hourOfArrival < hourOfExam || (minuteOfArrival <= minuteOfExam && hourOfArrival <= hourOfExam)){
  14.             int allMinutesOfExam = (hourOfExam * 60) + minuteOfExam;
  15.             int allMinuteesOfArrival = (hourOfArrival * 60) + minuteOfArrival;
  16.             int timeBefore30min = allMinutesOfExam - 30;
  17.             int time = allMinutesOfExam - allMinuteesOfArrival;
  18.             if (allMinuteesOfArrival < allMinutesOfExam && allMinuteesOfArrival >= timeBefore30min) {
  19.                 System.out.println("On Time");
  20.                     if (time < 60) {
  21.                         System.out.printf("%d minutes before the start", time);
  22.                     } else{
  23.                         int b = time / 60;
  24.                         int c = time % 60;
  25.                         if (c < 10) {
  26.                             System.out.printf("%d:0%d hours before the start",b,c);
  27.                         } else
  28.                             System.out.printf("%d:%d hours before the start",b,c);
  29.                     }
  30.  
  31.             } else {
  32.                 System.out.println("Early");
  33.                 if (time < 60) {
  34.                     System.out.printf("%d minutes before the start", time);
  35.                 } else{
  36.                     int b = time / 60;
  37.                     int c = time % 60;
  38.                     if (c < 10) {
  39.                         System.out.printf("%d:0%d hours before the start",b,c);
  40.                     } else
  41.                         System.out.printf("%d:%d hours before the start",b,c);
  42.                 }
  43.  
  44.             }
  45.  
  46.         } else {
  47.             System.out.println("Late");
  48.             int allMinutesOfExam = (hourOfExam * 60) + minuteOfExam;
  49.             int allMinutesOfArrival = (hourOfArrival * 60) + minuteOfArrival;
  50.             if (allMinutesOfArrival - allMinutesOfExam < 60)
  51.                 System.out.printf("%d minutes after the start", allMinutesOfArrival - allMinutesOfExam);
  52.             else {
  53.                 int a = allMinutesOfArrival - allMinutesOfExam;
  54.                 int b = a/60;
  55.                 int c = a%60;
  56.                 if(c<10){
  57.                     System.out.printf("%d:0%d hours after the start",b,c);
  58.                 }else
  59.                     System.out.printf("%d:%d hours after the start",b,c);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement