using static System.Console;
using System.Globalization;
const int ENTRANCE_FEE = 25;
const int MIN_CONTESTANTS = 0;
const int MAX_CONTESTANTS = 30;
string[] names = new string[MAX_CONTESTANTS];
char[] talents = new char[MAX_CONTESTANTS];
char[] talentCodes = { 'S', 'D', 'M', 'O' };
string[] talentCodesStrings = { "Singing", "Dancing", "Musical instrument", "Other" };
int[] counts = { 0, 0, 0, 0 };
numThisYear = getContestantNumber("this", MIN_CONTESTANTS, MAX_CONTESTANTS);
revenue = numThisYear * ENTRANCE_FEE;
getContestantData(numThisYear, names, talents, talentCodes, talentCodesStrings, counts);
getLists(numThisYear, talentCodes, talentCodesStrings, names, talents, counts);
public static int getContestantNumber(string when, int min, int max)
Write("Enter number of contestants {0} year >> ", when);
entryString = ReadLine();
while (num < min || num > max)
if (!int.TryParse(entryString, out num))
WriteLine("Format invalid");
Write("Enter number of contestants {0} year >> ", when);
entryString = ReadLine();
if (num < min || num > max)
WriteLine("Number must be between {0} and {1}", min, max);
Write("Enter number of contestants {0} year >> ", when);
entryString = ReadLine();
public static void displayRelationship(int numThisYear, int numLastYear)
if (numThisYear > 2 * numLastYear)
WriteLine("The competition is more than twice as big this year!");
if (numThisYear > numLastYear)
WriteLine("The competition is bigger than ever!");
if (numThisYear < numLastYear)
WriteLine("A tighter race this year! Come out and cast your vote!");
public static void getContestantData(int numThisYear, string[] names, char[] talents, char[] talentCodes, string[] talentCodesStrings, int[] counts)
Write("Enter contestant name >> ");
WriteLine("Talent codes are:");
for (int y = 0; y < talentCodes.Length; ++y)
WriteLine(" {0} {1}", talentCodes[y], talentCodesStrings[y]);
Write(" Enter talent code >> ");
if (!char.TryParse(ReadLine(), out talents[x]))
WriteLine("Invalid format - entry must be a single character");
for (int z = 0; z < talentCodes.Length; ++z)
if (talents[x] == talentCodes[z])
WriteLine("That is not a valid code");
Write(" Enter talent code >> ");
public static void getLists(int numThisYear, char[] talentCodes, string[] talentCodesStrings, string[] names, char[] talents, int[] counts)
WriteLine("\nThe types of talent are:");
for (x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]);
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
if (!char.TryParse(ReadLine(), out option))
WriteLine("Invalid format - entry must be a single character");
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
for (int z = 0; z < talentCodes.Length; ++z)
if (option == talentCodes[z])
WriteLine("{0} is not a valid code", option);
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
WriteLine("\nContestants with talent {0} are:", talentCodesStrings[pos]);
for (x = 0; x < numThisYear; ++x)
if (talents[x] == option)
WriteLine("No contestants had talent {0}", talentCodesStrings[pos]);
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
public static char[] talentCodes = { 'S', 'D', 'M', 'O' };
public static string[] talentStrings = { "Singing", "Dancing", "Musical instrument", "Other" };
set { this.name = value; }
get { return Convert.ToString(age); }
set { this.age = Convert.ToDouble(value); }
set { this.talent = value; }
get { return talentCode; }
bool validTalentCode = false;
for (int i = 0; i < Contestant.talentCodes.Length; ++i)
if (value == Contestant.talentCodes[i])
this.Talent = Contestant.talentStrings[i];
this.talentCode = Convert.ToChar("I");
set { this.fee = value; }
public class ChildContestant : Contestant
public ChildContestant(string name, char talentCode, double age)
this.TalentCode = talentCode;
this.Age = Convert.ToString(age);
public override string ToString()
return ("Child Contestant " + Name + " " + TalentCode.ToString() + " Fee " + Fee.ToString("C", CultureInfo.GetCultureInfo("en-US")));
public class TeenContestant : Contestant
public TeenContestant(string name, char talentCode, double age)
this.TalentCode = talentCode;
this.Age = Convert.ToString(age);
public override string ToString()
return ("Teen Contestant "+ Name + " " + TalentCode.ToString() + " Fee " + Fee.ToString("C", CultureInfo.GetCultureInfo("en-US")));
public class AdultContestant : Contestant
public AdultContestant(string name, char talentCode, double age)
this.TalentCode = talentCode;
this.Age = Convert.ToString(age);
public override string ToString()
return ("Adult Contestant " + Name + " " + TalentCode.ToString() + " Fee " + Fee.ToString("C", CultureInfo.GetCultureInfo("en-US")));