Advertisement
veronikaaa86

On Time For The Exam

Oct 31st, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. package Exam6March2016;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P03_OnTimeForTheExam {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int examHour = Integer.parseInt(scanner.nextLine());
  10.         int examMinutes = Integer.parseInt(scanner.nextLine());
  11.         int arriveHour = Integer.parseInt(scanner.nextLine());
  12.         int arriveMinutes = Integer.parseInt(scanner.nextLine());
  13.  
  14.         int allMinutesExam = (examHour*60)+examMinutes;
  15.         int allMinutesArrive = (arriveHour*60)+arriveMinutes;
  16.  
  17.         int hour = 0;
  18.         int minutes = 0;
  19.         int margin = 0;
  20.  
  21.         if (allMinutesExam<allMinutesArrive) {
  22.             margin = allMinutesArrive-allMinutesExam;
  23.             hour = margin/60;
  24.             minutes = margin%60;
  25.             if (hour<1) {
  26.                 System.out.printf("Late%n%d minutes after the start", minutes);
  27.             } else {
  28.                 System.out.printf("Late%n%d:%02d hours after the start", hour, minutes);
  29.             }
  30.         } else if (allMinutesExam>allMinutesArrive) {
  31.             margin = allMinutesExam-allMinutesArrive;
  32.             if (margin>30) {
  33.                 hour = margin/60;
  34.                 minutes = margin%60;
  35.                 if (hour<1) {
  36.                     System.out.printf("Early%n%d minutes before the start", minutes);
  37.                 } else {
  38.                     System.out.printf("Early%n%d:%02d hours before the start", hour, minutes);
  39.                 }
  40.             } else {
  41.                 minutes = margin%60;
  42.                 System.out.printf("On time%n%d minutes before the start", minutes);
  43.             }
  44.         } else {
  45.             System.out.printf("On time");
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement