Angel_Kalinkov

PBE-Coding101Exam-6March2016-OnTimeForTheExam_AngelKalinkov

Feb 2nd, 2018
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2.  
  3. class OnTimeForTheExam
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         byte examHour = byte.Parse(Console.ReadLine());
  8.         byte examMinutes = byte.Parse(Console.ReadLine());
  9.         byte arriveHour = byte.Parse(Console.ReadLine());
  10.         byte arriveMinutes = byte.Parse(Console.ReadLine());
  11.  
  12.         String late = "Late";
  13.         String onTime = "On time";
  14.         String early = "Early";
  15.         int examTimeToMin = examHour * 60 + examMinutes;
  16.         int arriveTimeToMin = arriveHour * 60 + arriveMinutes;
  17.         int difference = arriveTimeToMin - examTimeToMin;
  18.  
  19.         String studentArrival = late;
  20.         if (difference < -30)
  21.         {
  22.             studentArrival = early;
  23.         }
  24.         else if (difference <= 0)
  25.         {
  26.             studentArrival = onTime;
  27.         }
  28.         String result = "";
  29.         if (difference != 0)
  30.         {
  31.             int hoursDifference = Math.Abs(difference / 60);
  32.             int minutesDifference = Math.Abs(difference % 60);
  33.             if (hoursDifference > 0)
  34.             {
  35.                 result = ($"{hoursDifference}:{minutesDifference:D2} hours");
  36.             }
  37.             else
  38.             {
  39.                 result = minutesDifference + " minutes";
  40.             }
  41.             if (difference < 0)
  42.             {
  43.                 result += " before the start";
  44.             }
  45.             else
  46.             {
  47.                 result += " after the start";
  48.             }
  49.         }
  50.         Console.WriteLine(studentArrival);
  51.         if (result != null)
  52.         {
  53.             Console.WriteLine(result);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment