Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description of class members Fields: There are no fields for this class. Properties: TIME _ FORMAT this class variable is of type TimeFormat and it

Description of class members
Fields:
There are no fields for this class.
Properties:
TIME_FORMAT this class variable is of type
TimeFormat and it represents the intended
format of the ToString() method. This
field has private accessibility and it initializes
to TimeFormat.Hour12 at declaration.
A class member that is decorated with the
static keyword implies that only one
copy of this member exists and it is shared
by all objects of the class. i.e. If it is changed
then all object will see the new value
immediately.
A class method can only access other class
member (fields/properties/methods)
UML Class Diagram
$ -> static
--> private
+-> public
# -> protected
Programming II Time: enum, class variable Week03_Lab08
Winter 2024 Page 3 of 5
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 =0, int minutes =0) This is a public constructor that takes
two integer arguments with default values of 0. 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.
Again, use the d2 format specifier to get the leading zero.
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.

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_2

Step: 3

blur-text-image_3

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

Learn Mysql The Easy Way A Beginner Friendly Guide

Authors: Kiet Huynh

1st Edition

B0CNY7143T, 979-8869761545

More Books

Students also viewed these Databases questions

Question

Describe how the status of women varies worldwide.

Answered: 1 week ago