Advertisement
Samorokimetal

Navreme Za Izpit

Jan 4th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NavremeZaIzpit {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String ivalidTime = "Invalid time";
  8.  
  9.         System.out.print("Exam Hours: ");
  10.         int examHours = Integer.parseInt(scanner.nextLine());
  11.         if (!(examHours >= 0 && examHours < 24)) {
  12.             System.out.println();
  13.             System.out.print(ivalidTime);
  14.             return;
  15.         }
  16.  
  17.         System.out.print("Exam Minutes: ");
  18.         int examMinutes = Integer.parseInt(scanner.nextLine());
  19.         if (!(examMinutes >= 0 && examMinutes < 60)) {
  20.             System.out.println();
  21.             System.out.print(ivalidTime);
  22.             return;
  23.         }
  24.  
  25.         System.out.print("Arrival Hours: ");
  26.         int arrivalHours = Integer.parseInt(scanner.nextLine());
  27.         if (!(arrivalHours >= 0 && arrivalHours < 24)) {
  28.             System.out.println();
  29.             System.out.print(ivalidTime);
  30.             return;
  31.         }
  32.  
  33.         System.out.print("Arrival Minutes: ");
  34.         int arrivalMinutes = Integer.parseInt(scanner.nextLine());
  35.         if (!(arrivalMinutes >= 0 && arrivalMinutes < 60)) {
  36.             System.out.println();
  37.             System.out.print(ivalidTime);
  38.             return;
  39.         }
  40.         System.out.println();
  41.  
  42.         int examTime = (examHours * 60) + examMinutes;
  43.         int arrivalTime = (arrivalHours * 60) + arrivalMinutes;
  44.         int totalMinutesDiff = arrivalTime - examTime;
  45.         int hoursDiff = Math.abs(totalMinutesDiff / 60);
  46.         int minutesDiff = Math.abs(totalMinutesDiff % 60);
  47.        
  48.         if (totalMinutesDiff < -30) {
  49.             System.out.println("Early ");
  50.             if (hoursDiff == 1 && minutesDiff == 0) {
  51.                 System.out.printf("%d:%02d hour before the start", hoursDiff, minutesDiff);
  52.             } else {
  53.                 System.out.printf("%d:%02d hours before the start", hoursDiff, minutesDiff);
  54.             }
  55.         }
  56.         else if(totalMinutesDiff <= 0) {
  57.             System.out.print("On time");
  58.         }
  59.         else {
  60.             System.out.println("Late ");
  61.             if (hoursDiff == 1 && minutesDiff == 0) {
  62.                 System.out.printf("%d:%02d hour after the start", hoursDiff, minutesDiff);
  63.             } else {
  64.                 System.out.printf("%d:%02d hours after the start", hoursDiff, minutesDiff);
  65.             }
  66.         }
  67.  
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement