Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OnTimeForTheExam {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int examHour = Integer.parseInt(scanner.nextLine());
- int examMinutes = Integer.parseInt(scanner.nextLine());
- int arriveHour = Integer.parseInt(scanner.nextLine());
- int arriveMinutes = Integer.parseInt(scanner.nextLine());
- String late = "Late";
- String onTime = "On time";
- String early = "Early";
- int examTimeToMin = examHour * 60 + examMinutes;
- int arriveTimeToMin = arriveHour * 60 + arriveMinutes;
- int difference = arriveTimeToMin - examTimeToMin;
- String studentArrival = late;
- if (difference < -30) {
- studentArrival = early;
- } else if (difference <= 0) {
- studentArrival = onTime;
- }
- String result = "";
- if (difference != 0) {
- int hoursDifference = Math.abs(difference / 60);
- int minutesDifference = Math.abs(difference % 60);
- if (hoursDifference > 0) {
- result = String.format("%d:%02d hours", hoursDifference, minutesDifference);
- } else {
- result = minutesDifference + " minutes";
- }
- if (difference < 0) {
- result += " before the start";
- } else {
- result += " after the start";
- }
- }
- System.out.println(studentArrival);
- if (!result.isEmpty()) {
- System.out.println(result);
- }
- }
- }
Add Comment
Please, Sign In to add comment