-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathArmedForces.cs
42 lines (37 loc) · 1.2 KB
/
ArmedForces.cs
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
using System;
namespace Game
{
/// <summary>
/// Represents the armed forces for a country.
/// </summary>
public record ArmedForces
{
/// <summary>
/// Gets the number of men and women in the army.
/// </summary>
public int Army { get; init; }
/// <summary>
/// Gets the number of men and women in the navy.
/// </summary>
public int Navy { get; init; }
/// <summary>
/// Gets the number of men and women in the air force.
/// </summary>
public int AirForce { get; init; }
/// <summary>
/// Gets the total number of troops in the armed forces.
/// </summary>
public int TotalTroops => Army + Navy + AirForce;
/// <summary>
/// Gets the number of men and women in the given branch.
/// </summary>
public int this[MilitaryBranch branch] =>
branch switch
{
MilitaryBranch.Army => Army,
MilitaryBranch.Navy => Navy,
MilitaryBranch.AirForce => AirForce,
_ => throw new ArgumentException("INVALID BRANCH")
};
}
}