static void TaskB() { MyTime t = new MyTime(9, 2, 30); Console.WriteLine(t); Console.WriteLine("TimeSinceMidnight:"); Console.WriteLine(t.TimeSinceMidnight()); Console.WriteLine(new MyTime(24 * 60 * 60 - 1)); Console.WriteLine("Add one (s/m/h):"); t = t.AddOneSecond(); Console.WriteLine(t); t = t.AddOneMinute(); Console.WriteLine(t); t = t.AddOneHour(); Console.WriteLine(t); Console.WriteLine("AddSeconds:"); t = t.AddSeconds(-40000); Console.WriteLine(t); Console.WriteLine(new MyTime(23, 59, 59).AddSeconds(2)); Console.WriteLine("Difference:"); Console.WriteLine(MyTime.Difference(t, new MyTime(4, 20, 0))); MyTime t1 = new MyTime(7, 59, 59); Console.WriteLine("What lesson {0}: {1}", t1, t1.WhatLesson()); MyTime t2 = new MyTime(8, 0, 0); Console.WriteLine("What lesson {0}: {1}", t2, t2.WhatLesson()); MyTime t3 = new MyTime(9, 19, 59); Console.WriteLine("What lesson {0}: {1}", t3, t3.WhatLesson()); MyTime t4 = new MyTime(9, 20, 0); Console.WriteLine("What lesson {0}: {1}", t4, t4.WhatLesson()); MyTime t5 = new MyTime(17, 29, 59); Console.WriteLine("What lesson {0}: {1}", t5, t5.WhatLesson()); MyTime t6 = new MyTime(17, 30, 0); Console.WriteLine("What lesson {0}: {1}", t6, t6.WhatLesson()); }
public string WhatLesson() { if (this < new MyTime(8, 0, 0)) { return("пари ще не почались"); } MyTime tmp = new MyTime(this); tmp.Hour -= 8; int les_num = 1; while (les_num < 5 && (tmp >= new MyTime(1, 40, 0))) // Counting lessons and breaks 1st through 4th { les_num++; tmp.Hour -= 1; tmp.Minute -= 40; } if (les_num == 5 && (tmp >= new MyTime(1, 30, 0))) // after 5th lesson break is 10mins long { les_num++; tmp.Hour -= 1; tmp.Minute -= 30; } if (tmp < new MyTime(1, 20, 0)) { return($"{les_num}-{(les_num == 3 ? "я" : "а")} пара"); } else if (les_num < 6) { return($"перерва між {les_num}-ю та {les_num + 1}-ю парами"); } else { return("пари вже скінчились"); } }
public MyTime(MyTime other) { hour = other.hour; minute = other.minute; second = other.second; }
// Static Methods public static int Difference(MyTime t1, MyTime t2) { return(t1.TimeSinceMidnight() - t2.TimeSinceMidnight()); }