Advertisement
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 scanner = new Scanner(System.in);
- String ivalidTime = "Invalid time";
- System.out.print("Exam Hours: ");
- int examHours = Integer.parseInt(scanner.nextLine());
- if (!(examHours >= 0 && examHours < 24)) {
- System.out.println();
- System.out.print(ivalidTime);
- return;
- }
- System.out.print("Exam Minutes: ");
- int examMinutes = Integer.parseInt(scanner.nextLine());
- if (!(examMinutes >= 0 && examMinutes < 60)) {
- System.out.println();
- System.out.print(ivalidTime);
- return;
- }
- System.out.print("Arrival Hours: ");
- int arrivalHours = Integer.parseInt(scanner.nextLine());
- if (!(arrivalHours >= 0 && arrivalHours < 24)) {
- System.out.println();
- System.out.print(ivalidTime);
- return;
- }
- System.out.print("Arrival Minutes: ");
- int arrivalMinutes = Integer.parseInt(scanner.nextLine());
- if (!(arrivalMinutes >= 0 && arrivalMinutes < 60)) {
- System.out.println();
- System.out.print(ivalidTime);
- return;
- }
- System.out.println();
- int examTime = (examHours * 60) + examMinutes;
- int arrivalTime = (arrivalHours * 60) + arrivalMinutes;
- int totalMinutesDiff = arrivalTime - examTime;
- int hoursDiff = Math.abs(totalMinutesDiff / 60);
- int minutesDiff = Math.abs(totalMinutesDiff % 60);
- if (totalMinutesDiff < -30) {
- System.out.println("Early ");
- if (hoursDiff == 1 && minutesDiff == 0) {
- System.out.printf("%d:%02d hour before the start", hoursDiff, minutesDiff);
- } else {
- System.out.printf("%d:%02d hours before the start", hoursDiff, minutesDiff);
- }
- }
- else if(totalMinutesDiff <= 0) {
- System.out.print("On time");
- }
- else {
- System.out.println("Late ");
- if (hoursDiff == 1 && minutesDiff == 0) {
- System.out.printf("%d:%02d hour after the start", hoursDiff, minutesDiff);
- } else {
- System.out.printf("%d:%02d hours after the start", hoursDiff, minutesDiff);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement