Advertisement
StoyanKyrie11

Untitled

Jun 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class JustInTime {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int examHours = Integer.parseInt(scanner.nextLine());
  8. int examMinutes = Integer.parseInt(scanner.nextLine());
  9. int arrivalHours = Integer.parseInt(scanner.nextLine());
  10. int arrivalMinutes = Integer.parseInt(scanner.nextLine());
  11.  
  12. int examTime = (examHours * 60) + examMinutes;
  13. int arrivalTime = (arrivalHours * 60) + arrivalMinutes;
  14. int totalMinutesDifference = arrivalTime - examTime;
  15.  
  16. String studentArrivalTime = "Late";
  17.  
  18. if (totalMinutesDifference < -30) {
  19. studentArrivalTime = "Early";
  20. } else if (totalMinutesDifference <= 0) {
  21. studentArrivalTime = "On time";
  22. }
  23.  
  24. String result = "";
  25. if (totalMinutesDifference != 0) {
  26. int hoursDifference = Math.abs(totalMinutesDifference / 60);
  27. int minutesDifference = Math.abs(totalMinutesDifference % 60);
  28. if(hoursDifference > 0) {
  29. result = String.format("%d:%02d", hoursDifference, minutesDifference);
  30. } else {
  31. result = minutesDifference + " minutes";
  32. }
  33. if (totalMinutesDifference < 0) {
  34. result += " before the start";
  35. } else {
  36. result += " after the start";
  37. }
  38. }
  39. System.out.println(studentArrivalTime);
  40. if(!result.isEmpty()) {
  41. System.out.println(result);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement