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