Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

It would be perfectly reasonable for the Time2 class of Fig. 10.5 to represent t

ID: 441318 • Letter: I

Question

It would be perfectly reasonable for the Time2 class of Fig. 10.5 to represent the time internally as the number of seconds since midnight rather than the three integer values hour, minute, and second. Clients could use the same public methods and properties to get the same results. Modify the Time2 class of Fig. 10.5 to implement the Time2 as the number of seconds since midnight and show that no charge is visible to the clients of the class by using the same test application from Fig. 10.6. here are fig10.5 and 10.6 //10.5 using System; public class Time2 { private int hour; //0-23 private int minute; //0-59 private int second;//0-59 public Time2(int h = 0, int m = 0, int s = 0) { SetTime(h, m, s); } public Time2 (Time2 time) : this (time.Hour, time.Minute, time.Second) { } public void SetTime(int h, int m, int s) { Hour = h; Minute = m; Second = s; } public int Hour { get { return hour; } set { if (value >= 0 && value < 24) hour = value; else throw new ArgumentOutOfRangeException("hour", value, "hour must be 0-23"); } } public int Minute { get { return minute; } set { if (value >= 0 && value < 60) minute = value; else throw new ArgumentOutOfRangeException("minute", value, "minute must be 0-59"); } } public int Second { get { return second; } set { if (value >= 0 && value < 60) second = value; else throw new ArgumentOutOfRangeException("second", value, "second must be 0-59"); } } public string ToUniversalString() { return string.Format("{0:D2}:{1:D2}:{2:D2}", Hour, Minute, Second); } public override string ToString() { return string.Format("{0}:{1:D2}:{2:D2} {3}", ((Hour == 0 || Hour == 12) ? 12 : Hour % 12),Minute, Second, (Hour < 12 ? "AM " : "PM")); } } //10.6 using System; public class Time2Test { public static void main (String[] args) { Time2 t1 = new Time2(); Time2 t2 = new Time2(2); Time2 t3 = new Time2 (21, 34); Time2 t4 = new Time2(12, 25, 42); Time2 t5 = new Time2 (t4); Time2 t6; Console.WriteLine ("constructed with : "); Console.WriteLine ( " t1:all arguments defaulted"); Console.WriteLine ( " {0}", t1.ToUniversalString()); Console.WriteLine ( " {0} ", t1.ToString()); Console.WriteLine(" t2 : hour specified: minute and second defaulted"); Console.WriteLine ( " {0}", t2.ToUniversalString()); Console.WriteLine ( " {0} ", t2.ToString()); Console.WriteLine ( " t3: hour and minute specified; second defaulted"); Console.WriteLine ( " {0}", t3.ToUniversalString()); Console.WriteLine ( " {0} ", t3.ToString()); Console.WriteLine ( " t4: hour, minute and second specified"); Console.WriteLine ( " {0}", t4.ToUniversalString()); Console.WriteLine ( " {0} ", t4.ToString()); Console.WriteLine ( " t5:Time2 object t4 specified"); Console.WriteLine ( " {0}", t5.ToUniversalString()); Console.WriteLine ( " {0} ", t5.ToString()); try { t6 = new Time2 (27, 74, 99); } catch ( ArgumentOutOfRangeException ex) { Console.WriteLine ( " Excemption while initializing t6:"); Console.WriteLine (ex.Message); } } }

Explanation / Answer

WHAT IS THE QUESTION?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote