Question: C# APPLICATION Create a new C# test console application which should do the following: The data for the entered time objects should be kept in

C# APPLICATION

Create a new C# test console application which should do the following:

The data for the entered time objects should be kept in a list of time2 objects ( List) so you can use LINQ to run the queries that will produce the reports

Start with a loop to ask the user to enter data for a number of time2 and time2tz objects. The user should be given the choice to keep entering data or stop after data for each object is entered.

Example Output:

Which type of object you wish to enter?:

1 time2

2 time2tz

3 Stop entering data

1

Enter Hours:

6

Enter Minutes:

25

Enter Seconds:

50

Which type of object you wish to enter?:

1 time2

2 time2tz

3 Stop entering data

2

Enter Hours:

15

Enter Minutes:

12

Enter Seconds:

24

Enter timezone

CST

Which type of object you wish to enter?:

1 time2

2 time2tz

3 Stop entering data

3

What report do you want:

1 All objects

2 All objects with AM times

3 All objects with PM times

4 - QUIT

Display the list of requested objects in increasing order

After the report is produced, the user should have the choice to produce another report or quit.

Extra credit: (10 Points) Have your classes throw an exception when adding time takes the time value to more than 23:59:59 and modify the Test program to handle the exception.

/ Fig. 10.5: Time2.cs // Time2 class declaration with overloaded constructors. using System; // for class ArgumentOutOfRangeException

public class Time2 { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 - 59 // constructor can be called with zero, one, two or three arguments

// Time2 constructor: another Time2 object supplied as an argument public Time2(int h = 0, int m = 0, int s = 0) { SetTime(h, m, s); // invoke SetTime to validate time } // end Time2 three-argument constructor public Time2(Time2 time) : this(time.Hour, time.Minute, time.Second) { } // set a new time value using universal time; ensure that // the data remains consistent by setting invalid values to zero public void SetTime(int h, int m, int s) { Hour = h; // set the Hour property Minute = m; // set the Minute property Second = s; // set the Second property } // end method SetTime

// property that gets and sets the hour public int Hour { get { return hour; } // end get set { if (value >= 0 && value < 24) hour = value; else throw new ArgumentOutOfRangeException("Hour", value, "Hour must be 0-23"); } // end set } // end property Hour // property that gets and sets the minute public int Minute { get { return minute; } // end get set { if (value >= 0 && value < 60) minute = value; else throw new ArgumentOutOfRangeException("Minute", value, "Minute must be 0-59"); } // end set } // end property Minute

// property that gets and sets the second public int Second { get { return second; } // end get set { if (value >= 0 && value < 60) second = value; else throw new ArgumentOutOfRangeException("Second", value, "Second must be 0-59"); } // end set } // end property Second

// convert to string in universal-time format (HH:MM:SS) public string ToUniversalString() { return string.Format("{0:D2}:{1:D2}:{2:D2}", Hour, Minute, Second); } // end method ToUniversalString

// convert to string in standard-time format (H:MM:SS AM or PM) 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")); } // end method ToString }

//Time2tz.cs

using System; public class Program { static void Main(string[] args) { var dateTime = DateTime.Now;

Console.WriteLine(dateTime);

// Display Time Zone of your System

Console.WriteLine(TimeZoneInfo.Local);

// Convert Current Date Time to EST Date Time Console.WriteLine(" Eastern Standard Time"); var est = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); var eastern = TimeZoneInfo.ConvertTime(dateTime, est); Console.WriteLine(eastern);

// Convert Current Date Time to CST Date Time Console.WriteLine(" Central Standard Time"); var cst = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var central = TimeZoneInfo.ConvertTime(dateTime, cst); Console.WriteLine(central);

// Convert Current Date Time to MST Date Time Console.WriteLine(" Mountain Standard Time"); var mst = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time"); var mountain = TimeZoneInfo.ConvertTime(dateTime, mst); Console.WriteLine(mountain);

// Convert Current Date Time to PST Date Time Console.WriteLine(" Pacific Standard Time"); var pst = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); var pacific = TimeZoneInfo.ConvertTime(dateTime, pst); Console.WriteLine(pacific);

Console.ReadLine(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!