Advertisement
veronikaaa86

08. On Time for the Exam

Nov 14th, 2021
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. package exerciseAdvConditionalStatements;
  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 examTime = (examHour * 60) + examMin;
  15. int arrivalTime = (hourOfArrival * 60) + minOfArrival;
  16.  
  17. int diff = Math.abs(examTime - arrivalTime);
  18. if (examTime < arrivalTime) {
  19. System.out.println("Late");
  20. if (diff >= 60) {
  21. int hour = diff / 60;
  22. int min = diff % 60;
  23. System.out.printf("%d:%02d hours after the start", hour, min);
  24. } else {
  25. System.out.printf("%d minutes after the start", diff);
  26. }
  27.  
  28. } else if (examTime == arrivalTime || (diff >= 1 && diff <= 30)) {
  29. System.out.println("On time");
  30. if (diff >= 1 && diff <= 30) {
  31. System.out.printf("%d minutes before the start", diff);
  32. }
  33.  
  34. } else {
  35. System.out.println("Early");
  36. if (diff >= 60) {
  37. int hour = diff / 60;
  38. int min = diff % 60;
  39. System.out.printf("%d:%02d hours before the start", hour, min);
  40. } else {
  41. System.out.printf("%d minutes before the start", diff);
  42. }
  43.  
  44. }
  45. }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement