-
Notifications
You must be signed in to change notification settings - Fork 0
/
SweepStakes.cs
59 lines (57 loc) · 2.03 KB
/
SweepStakes.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sweepStakes
{
public class SweepStakes
{
//member variables
Dictionary<int, Contestant> participants = new Dictionary<int, Contestant>();
Contestant winner;
string name;
//constructor
public SweepStakes(string name)
{
this.name = name;
}
//member methods
public void RegisterContestant(Contestant contestant)
{
participants.Add(contestant.registrationNumber, contestant);
}
public string PickWinner()
{
Random rand = new Random();
List<int> keylist = new List<int>(participants.Keys);
int randomkey = keylist[rand.Next(keylist.Count)];
winner = participants[randomkey];
return winner.firstName;
}
public void PrintWinner(Contestant contestant)
{
foreach (KeyValuePair<int, Contestant> contest in participants)
{
if (contestant.firstName == winner.firstName)
{
Console.WriteLine($"Contestant Id: {contestant.registrationNumber} First name: {contestant.firstName}" +
$"Last name: {contestant.lastName} Email address: {contestant.emailAddress} ");
}
}
}
public void PrintContestantInfo(Contestant contestant)
{
Console.WriteLine("Please enter an contestants name: ");
string value = Console.ReadLine();
foreach(KeyValuePair<int, Contestant> contest in participants)
{
if(contestant.firstName == value)
{
Console.WriteLine($"Contestant Id: {contestant.registrationNumber} First name: {contestant.firstName}" +
$"Last name: {contestant.lastName} Email address: {contestant.emailAddress} ");
}
}
}
}
}