16225

Задача 3.1

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