Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C#, Console App (.NET Framework) Please provide the code with Visual Studio Studio screenshot please and thank you. You will learn about enums, static

In C#, Console App (.NET Framework)

Please provide the code with Visual Studio Studio screenshot please and thank you.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

You will learn about enums, static members and default arguments. Enums An enum is a user-define type like a class. However, all the members are constants with implied values. It provides an efficient way of defining a set of named integral constants such as the days of the week or months of the year or even the set of pre-defined colors. It supports a more robust programming style e.g. If you have a method that expects a month as an argument of type to a string, you will have do lots of defensive programming, instead define an enum type that has the 12 months. During development, the compiler will do the necessary checks for the require type hence you will do less programming. Static members The static decorator when used on a member indicates that member belongs to the type rather than an object. You will access that member using the type rather than an object reference. Static methods or properties may only access other static members. The only instance member that can be accessed is the constructor. You can recognize an instance member by the absence of the static modifier. Instance methods are able to access other instance members as well as class members.| The TimeFormat Enum Sometimes you don't even care about the underlining values as in this case or, (Maritial status: Single, Married, Widowed etc.), (Sale status: Confirmed, Shipped, Paid etc.) You may define/code this type in the Time. cs file, but it should be external to the Time class. The Time Class Code the Time class below: This class comprise of six members: a field, two properties and two methods and a constructor a SetTimeFormat() and a Tostring() method. All the fields are private and all the methods are public Description of class members Fields: There are no fields for this class. Properties: by all objects of the class. i.e. If it is changed TIME_FORMAT - this class variable is of type then all object will see the new value TimeFormat and it represents the intended immediately. format of the ToString( ) method. This field has private accessibility and it initializes A class method can only access other class to TimeFormat. Hour12 at declaration.| member (fields/properties/methods) Hour - this is an integer representing the hour value this object. This property has public read access and the setter is missing. Minute - this is an integer representing the minute value this object. This property has public read access and the setter is missing. Constructor: public Time(int hours =, int minutes = ) - This is a public constructor that takes two integer arguments with default values of . If checks if the first argument is between 0 and 24 it assigns it to the Hour property otherwise a value of 0 is assign to the hour property. Similarly the second argument is check if it is between 0 and 60 then it is assigned to the Minute property otherwise a value of 0 is assigned to the Minute property. Methods: public override string ToString( ) - This public method overrides the ToString of the object class. It does not take any argument and returns a string representation of the object. The return value will depend on the field TIME_FORMAT value of the class. So it is a good plan if you use a switch statement to handle the three possibilities. Your switch statement should check the value of the TIME_FORMAT field. If you have a Time object with the hours value as 18 and the minutes value as 5 then the print out of the object will be "1805" if TIME_FORMAT is set to TimeFormat.MIL. Use the d2 format specifier to get the leading zero. "18:05" if TIME_FORMAT is set to TimeFormat.HOUR24. implement this functionality Again, use the d2 format specifier to get the leading zero. A switch statement is "6:05 PM" if TIME_FORMAT is set to TimeFormat.HOUR12. Again, use the d2 format specifier to get the leading zero. public static void SetTimeFormat(TimeFormat time_format)-This a class method that is public. It takes a single TimeFormat argument and assigns it to the static TIME_FORMAT field. This method must be static because it needs to access a static field. Test Harness Insert the following code statements in your Program.cs file: Your output will look like below: Time format is Hour 12 9:35 AM 6:05PM 8:00PM 10:00AM 0:00AM Setting time format to Mil 0935 1805 2000 1000 0000 Setting time format to Hour 24 09:35 18:05 20:00 10:00 00:00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

Influences on Nonverbal Communication?

Answered: 1 week ago