Advertisement
veronikaaa86

08. On Time for the Exam

Jun 20th, 2021
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package advancedConditionalStatements;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P08OnTimeForTheExam {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. int examHour = Integer.parseInt(scanner.nextLine());
  10. int examMin = Integer.parseInt(scanner.nextLine());
  11. int hourOfArrival = Integer.parseInt(scanner.nextLine());
  12. int minOfArrival = Integer.parseInt(scanner.nextLine());
  13.  
  14. int examAllMinutes = (examHour * 60) + examMin;
  15. int arriveAllMinutes = (hourOfArrival * 60) + minOfArrival;
  16.  
  17. int diffMin = Math.abs(examAllMinutes - arriveAllMinutes);
  18. int hour = diffMin / 60;
  19. int min = diffMin % 60;
  20. if (examAllMinutes < arriveAllMinutes) {
  21. System.out.println("Late");
  22. if (hour >= 1) {
  23. System.out.printf("%d:%02d hours after the start%n", hour, min);
  24. } else {
  25. System.out.printf("%d minutes after the start%n", min);
  26. }
  27. } else if (examAllMinutes == arriveAllMinutes || (diffMin >= 0 && diffMin <= 30)) {
  28. System.out.println("On time");
  29. if (diffMin > 0) {
  30. System.out.printf("%d minutes before the start%n", diffMin);
  31. }
  32. } else {
  33. System.out.println("Early");
  34. if (hour >= 1) {
  35. System.out.printf("%d:%02d hours before the start%n", hour, min);
  36. } else {
  37. System.out.printf("%d minutes before the start%n", min);
  38. }
  39. }
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement