Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package L03ConditionalStatementsAdvanced.Exercises;
- import java.util.Scanner;
- public class P08OnTimeForTheExam {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //1. Прочетаме входните данни
- //2. Прехвърлим всичко в минуте -> общо минути за изпита, общо минути на пристигане
- //3. Разликата от общите минути на изпита и общите минути на пристигане
- //4. Проверяваме дали е закъснял
- // Вложена проверка дали е закъснял повече от час или не
- int examHour = Integer.parseInt(scanner.nextLine());
- int examMinutes = Integer.parseInt(scanner.nextLine());
- int arrivalHour = Integer.parseInt(scanner.nextLine());
- int arrivalMinutes = Integer.parseInt(scanner.nextLine());
- int examTotalMinutes = examHour * 60 + examMinutes;
- int arrivalTotalMinutes = arrivalHour * 60 + arrivalMinutes;
- int diff = Math.abs(arrivalTotalMinutes - examTotalMinutes);
- if (arrivalTotalMinutes > examTotalMinutes){
- System.out.println("Late");
- if(diff < 60){
- System.out.printf("%d minutes after the start", diff);
- }else {
- int hour = diff / 60;
- int minutes = diff % 60;
- System.out.printf("%d:%02d hours after the start", hour, minutes);
- }
- }else if(diff <= 30){
- System.out.println("On time");
- if (examTotalMinutes != arrivalTotalMinutes){
- System.out.printf("%d minutes before the start", diff);
- }
- }else {
- System.out.println("Early");
- if(diff < 60){
- System.out.printf("%d minutes before the start", diff);
- }else {
- int hour = diff / 60;
- int minutes = diff % 60;
- System.out.printf("%d:%02d hours before the start", hour, minutes);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement