Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. import static java.lang.System.in;
  4.  
  5. public class p14_OnTime {
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(in);
  8. while (true) {
  9. int ExamHour = Integer.parseInt(sc.nextLine());
  10. int ExamMin = Integer.parseInt(sc.nextLine());
  11. int ArrivalHour = Integer.parseInt(sc.nextLine());
  12. int ArrivalMin = Integer.parseInt(sc.nextLine());
  13. int differenceInMin = ((ExamHour * 60) + ExamMin) - ((ArrivalHour * 60) + ArrivalMin);
  14. //On time
  15. if (((ExamHour * 60) + ExamMin) >= ((ArrivalHour * 60) + ArrivalMin)) {
  16. if (differenceInMin == 0) {
  17. System.out.println("On Time \n");
  18. } else if (differenceInMin <= 30) {
  19. System.out.println("On Time");
  20. System.out.printf("%d minutes before the start \n", differenceInMin);
  21. } else {
  22. System.out.println("Early");
  23. int HH = differenceInMin / 60;
  24. int MM = differenceInMin % 60;
  25. if (differenceInMin < 60) {
  26. System.out.printf("%d minutes before the start \n", differenceInMin);
  27. } else if (MM < 10) {
  28. System.out.printf("%d:0%d hours before the start \n", HH, MM);
  29. } else
  30. System.out.printf("%d:%d hours before the start \n", HH, MM);
  31. }
  32. } else if (((ArrivalHour * 60) + ArrivalMin) > ((ExamHour * 60) + ExamMin)) {
  33. System.out.println("Late");
  34. int HH = Math.abs(differenceInMin) / 60;
  35. int MM = Math.abs(differenceInMin) % 60;
  36. if (Math.abs(differenceInMin) < 60) {
  37. System.out.printf("%d minutes after the start \n", Math.abs(differenceInMin));
  38. } else if (MM < 10) {
  39. System.out.printf("%d:0%d hours after the start \n", HH, MM);
  40. } else System.out.printf("%d:%d hours after the start \n", HH, MM);
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement