Advertisement
Dido09

OnTimeForTheExam

Oct 1st, 2019
176
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.  
  7. int examHours = Integer.parseInt(scanner.nextLine());
  8. int examMins = Integer.parseInt(scanner.nextLine());
  9. int arrivalHours = Integer.parseInt(scanner.nextLine());
  10. int arrivalMins = Integer.parseInt(scanner.nextLine());
  11.  
  12. int examTimeInMins = examHours * 60 + examMins;
  13. int arrivalTimeInMins = arrivalHours * 60 + arrivalMins;
  14.  
  15. int time = examTimeInMins - arrivalTimeInMins;
  16.  
  17. if(time < 0){
  18. System.out.println("Late");
  19. int hours = Math.abs(time) / 60;
  20. int mins = Math.abs(time) % 60;
  21. if(time > -60){
  22. System.out.printf("%d minutes after the start", mins);
  23. }else{
  24. System.out.printf("%d:%02d hours after the start", hours, mins);
  25. }
  26. }else if(time <= 30){
  27. System.out.println("On time");
  28. if(time > 0){
  29. System.out.printf("%d minutes before the start", time);
  30. }
  31. }else{
  32. System.out.println("Early");
  33. int hours = time / 60;
  34. int mins = time % 60;
  35. if(time >= 60){
  36. System.out.printf("%d:%02d hours before the start",hours, mins );
  37. }else{
  38. System.out.printf("%d minutes before the start", mins);
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement