Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NaVremeZaIzpit {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int examH = Integer.parseInt(sc.nextLine());
- int examMin = Integer.parseInt(sc.nextLine());
- int arrivalH = Integer.parseInt(sc.nextLine());
- int arrivalMin = Integer.parseInt(sc.nextLine());
- String late = "Late";
- String onTime = "On time";
- String early = "Early";
- int examTime = examH * 60 + examMin;
- int arrivalTime = arrivalH * 60 + arrivalMin;
- int totalMinutesDifference = arrivalTime - examTime;
- String studentArrival = late;
- if (totalMinutesDifference < -30) {
- studentArrival = early;
- } else if (totalMinutesDifference <= 0) {
- studentArrival = onTime;
- }
- 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 hours", hoursDifference,
- minutesDifference);
- } else {
- result = minutesDifference + " minutes";
- }
- if (totalMinutesDifference < 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