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