danisun18

On Time for the Exam

Feb 2nd, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 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. int timeExam = Integer.parseInt(scanner.nextLine());
  7. int minuteExam = Integer.parseInt(scanner.nextLine());
  8. int timeArrival = Integer.parseInt(scanner.nextLine());
  9. int minuteArrival = Integer.parseInt(scanner.nextLine());
  10.  
  11.  
  12. int Exam = timeExam * 60 + minuteExam;
  13. int Arrival = timeArrival * 60 + minuteArrival;
  14. int difference1 = Exam - Arrival;
  15. int difference2 = Arrival - Exam;
  16.  
  17. if (difference1 > 0 && difference1 <= 30) {
  18. System.out.printf("On time %n%d minutes before the start", difference1);
  19. } else if (difference1 > 30 && difference1 <= 59) {
  20. System.out.printf("Early %n%d minutes before the start", difference1);
  21. } else if (difference1 > 59) {
  22. int hh = difference1 / 60;
  23. int mm = difference1 % 60;
  24. System.out.printf("Early %n%d:%02d hours before the start", hh, mm);
  25. }else {
  26. System.out.println("On time");
  27. }
  28. if (difference2 > 0 && difference2 <= 59) {
  29. System.out.printf("Late %n %d minutes after the start", difference2);
  30. } else if (difference2 > 59) {
  31. int hh = difference2 / 60;
  32. int mm = difference2 % 60;
  33. System.out.printf("Late %n%d:%02d hours after the start", hh, mm);
  34. }
  35.  
  36.  
  37. }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment