Advertisement
Ivakis

On time for the exam

Aug 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. * Created by User on 17.8.2017 г..
  5. */
  6. public class demo {
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int examHour = Integer.parseInt(scanner.nextLine());
  12. int examMin = Integer.parseInt(scanner.nextLine());
  13. int arrivalHour = Integer.parseInt(scanner.nextLine());
  14. int arrivalMin = Integer.parseInt(scanner.nextLine());
  15.  
  16. int examMinutes = examHour * 60 + examMin;
  17. int arrivalMinutes = arrivalHour * 60 + arrivalMin;
  18.  
  19. int timeDiff = examMinutes - arrivalMinutes;
  20.  
  21. if(timeDiff < 0){
  22.  
  23. int hour = Math.abs(timeDiff) / 60;
  24. int mins = Math.abs(timeDiff) % 60;
  25.  
  26. if (hour > 0){
  27. System.out.printf
  28. ("Late\n%d:%02d hours after the start", hour, mins);
  29. }else{
  30. System.out.printf
  31. ("Late\n%d minutes after the start",mins);
  32. }
  33. }if(timeDiff >= 0 && timeDiff <= 30 ){
  34.  
  35. int mins = Math.abs(timeDiff) % 60;
  36.  
  37. if(mins == 0) {
  38. System.out.println("On time");
  39. }else {
  40. System.out.printf("On time\n%d minutes before the start", mins);
  41. }
  42. }if(timeDiff > 30){
  43.  
  44. int hour = Math.abs(timeDiff) / 60;
  45. int mins = Math.abs(timeDiff) % 60;
  46.  
  47. if (hour > 0){
  48. System.out.printf
  49. ("Early\n%d:%02d hours before the start", hour, mins);
  50. }else{
  51. System.out.printf
  52. ("Early\n%d minutes before the start", mins);
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement