Guest User

On time for exam

a guest
May 20th, 2017
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. /**
  6.  * Created by user on 20/05/17.
  7.  */
  8. public class P03OnTimeForExam {
  9.  
  10.     public static void main(String[] args) {
  11.  
  12.         Scanner input = new Scanner(System.in);
  13.         int examHour = Integer.parseInt(input.nextLine());
  14.         int examMinutes = Integer.parseInt(input.nextLine());
  15.         int myHour = Integer.parseInt(input.nextLine());
  16.         int myMinutes = Integer.parseInt(input.nextLine());
  17.  
  18.         int difference = (examHour * 60 + examMinutes) - (myHour * 60 +myMinutes);
  19.         int hour = difference/60;
  20.         int minutes = difference%60;
  21.  
  22.  
  23.  
  24.         if (difference > 30) {
  25.             System.out.println("Early");
  26.  
  27.             if (difference>=31 && difference<=59) {
  28.                 System.out.printf("%02d minutes before the start", difference);
  29.  
  30.             }else {
  31.                 System.out.printf("%d:%02d hours before the start", hour, minutes);
  32.             }
  33.  
  34.  
  35.  
  36.         }else if ((difference <= 30 && difference >0) || difference ==0){
  37.             System.out.println("On time");
  38.  
  39.             if (difference<=30 && difference >0) {
  40.                 System.out.printf("%d minutes before the start", difference);
  41.             }else {
  42.                 //empty
  43.             }
  44.  
  45.         }else if (difference<0) {
  46.             System.out.println("Late");
  47.  
  48.             if (difference<=-1 && difference >=-9 ) {
  49.                 System.out.printf("%02d minutes after the start", Math.abs(difference));
  50.  
  51.             }else if (difference <-9&& difference >=-59) {
  52.                 System.out.printf("%d minutes after the start", Math.abs(difference));
  53.  
  54.             }else {
  55.                 System.out.printf("%d:%02d hours after the start", Math.abs(hour), Math.abs(minutes));
  56.             }
  57.  
  58.         }
  59.  
  60.  
  61.  
  62.     }
  63. }
Add Comment
Please, Sign In to add comment