-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (72 loc) · 2.04 KB
/
Program.cs
File metadata and controls
87 lines (72 loc) · 2.04 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//Module 5 2 Encapsulation
using System;
using System.Collections.Generic;
// 1. Person class
public class Person
{
private string _name;
private int _age;
private string _emailAddress;
public string Name
{
get { return _name; }
set { _name = value; }
}
public int Age
{
get { return _age; }
set { _age = value; }
}
public string EmailAddress
{
get { return _emailAddress; }
set { _emailAddress = value; }
}
public override string ToString()
{
return $"Name: {Name}, Age: {Age}, Email: {EmailAddress}";
}
}
// 2. PlayersInfo class
public class PlayersInfo
{
private List<Person> _players = new List<Person>();
public void AddPlayer(Person player)
{
_players.Add(player);
}
public void DisplayPlayers()
{
Console.WriteLine("All Players Information:");
foreach (var player in _players)
{
Console.WriteLine(player);
}
}
}
class Program
{
static void Main(string[] args)
{
// You may not change anything from the main method.
Console.WriteLine("Enter a person's name: ");
string name = Console.ReadLine();
Console.WriteLine("Enter age: ");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("Enter e-mail address: ");
string address = Console.ReadLine();
// Demonstration for Person class
Person person = new Person();
person.Name = name;
person.Age = age;
person.EmailAddress = address;
Console.WriteLine(person);
// Demonstration for PlayersInfo class
PlayersInfo playersInfo = new PlayersInfo();
playersInfo.AddPlayer(person);
playersInfo.AddPlayer(new Person { Name = "Adil Kabbari", Age = 20, EmailAddress = "adil.kabbari@gmail.com" });
playersInfo.AddPlayer(new Person { Name = "Mike C", Age = 40, EmailAddress = "mike.c@gmail.com" });
playersInfo.DisplayPlayers();
Console.ReadLine();
}
}