veronikaaa86

08. On Time for the Exam

Jan 23rd, 2022
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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 examMinutes = Integer.parseInt(scanner.nextLine());
  11. int hourOfArrival = Integer.parseInt(scanner.nextLine());
  12. int minOfArrival = Integer.parseInt(scanner.nextLine());
  13.  
  14. int examTime = (examHour * 60) + examMinutes;
  15. int arrivalTime = (hourOfArrival * 60) + minOfArrival;
  16.  
  17. int diff = Math.abs(examTime - arrivalTime);
  18.  
  19. //exam -> 9:30 = (9 * 60) + 30 = 570
  20. //arr -> 9:50 = (9 * 60) + 50 = 590
  21. if (examTime < arrivalTime) {
  22. System.out.println("Late");
  23.  
  24. if (diff >= 60) {
  25. int hour = diff / 60;
  26. int min = diff % 60;
  27. System.out.printf("%d:%02d hours after the start", hour, min);
  28. } else {
  29. System.out.printf("%d minutes after the start", diff);
  30. }
  31.  
  32. } else if ((examTime == arrivalTime) || (diff <= 30)) {
  33. System.out.println("On time");
  34. if (diff >= 1 && diff <= 30) {
  35. System.out.printf("%d minutes before the start", diff);
  36. }
  37.  
  38. } else {
  39. System.out.println("Early");
  40. if (diff >= 60) {
  41. int hour = diff / 60;
  42. int min = diff % 60;
  43. System.out.printf("%d:%02d hours before the start", hour, min);
  44. } else {
  45. System.out.printf("%d minutes before the start", diff);
  46. }
  47. }
  48. }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment