Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OnTimeForTheExam {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int examHours = Integer.parseInt(scanner.nextLine());
  8. int examMinutes = Integer.parseInt(scanner.nextLine());
  9. int arriveHours = Integer.parseInt(scanner.nextLine());
  10. int arriveMinutes = Integer.parseInt(scanner.nextLine());
  11.  
  12. int examTime = (examHours * 60) + examMinutes;
  13. int arrivalTime = (arriveHours * 60) + arriveMinutes;
  14. int hours = 0;
  15. int minutes = 0;
  16.  
  17.  
  18. if (arrivalTime > examTime) {
  19. int timeLate = arrivalTime - examTime;
  20. if (timeLate <= 59) {
  21. System.out.println("Late");
  22. System.out.printf("%02d minutes after the start", timeLate);
  23. } else if (timeLate >= 60) {
  24. hours = timeLate / 60;
  25. minutes = timeLate % 60;
  26. System.out.println("Late");
  27. System.out.printf("%d:%02d hours after the start", hours, minutes);
  28. }
  29. } else if (arrivalTime < examTime) {
  30. int timeEarly = examTime - arrivalTime;
  31. if (timeEarly > 0 && timeEarly <= 30) {
  32. System.out.println("On time");
  33. System.out.printf("%d minutes before the start", timeEarly);
  34. } else if (timeEarly > 30 && timeEarly <= 59) {
  35. System.out.println("Early");
  36. System.out.printf("%02d minutes before the start", timeEarly);
  37. } else if (timeEarly >= 60) {
  38. hours = timeEarly / 60;
  39. minutes = timeEarly % 60;
  40. System.out.println("Early");
  41. System.out.printf("%d:%02d hours before the start", hours, minutes);
  42. }
  43. } else {
  44. System.out.println("On time");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement