-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFig-8.06 - Time3.cs
More file actions
67 lines (54 loc) · 1.44 KB
/
Copy pathFig-8.06 - Time3.cs
File metadata and controls
67 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Fig. 8.6: Time3.cs
// A classe Time3 fornece acessores de propriedade get e set.
using System;
public class Time3
{
private int hour;
private int minute;
private int second;
public Time3()
{ SetTime(0, 0, 0); }
public Time3(int hour)
{ SetTime(hour, 0, 0); }
public Time3(int hour, int minute)
{ SetTime(hour, minute, 0); }
public Time3(int hour, int minute, int second)
{ SetTime(hour, minute, second); }
public Time3(Time3 time)
{ SetTime(time.hour, time.minute, time.second); }
public void SetTime(int hourValue, int minuteValue, int secondValue)
{
Hour = hourValue; // Chama o conjunto de propriedades Hour.
Minute = minuteValue; // Chama o conjunto de propriedades Minute.
Second = secondValue; // Chama o conjunto de propriedades Second.
}
// Propriedade Hour.
public int Hour
{
get { return hour; }
set { hour = ((value >= 0 && value < 24) ? value : 0); }
}
// Propriedade Minute.
public int Minute
{
get { return minute; }
set { minute = ((value >= 0 && value < 60) ? value : 0); }
}
// Propriedade Second.
public int Second
{
get { return second; }
set { second = ((value >= 0 && value < 60) ? value : 0); }
}
public string ToUniversalString()
{
return String.Format($"{hour:D2}:{minute:D2}:{second:D2}");
}
public string ToStandardString()
{
return String.Format("{0}:{1:D2}:{2:D2} {3}",
((Hour == 12 || Hour == 0) ? 12 : Hour % 12),
Minute, Second, (Hour < 12 ? "AM" : "PM")
);
}
}