In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults. Modify the Contestant class to contain a field that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant. Child contestants are 12 years old and younger, and their entry fee is $15. Teen contestants are between 13 and 17 years old, inclusive, and their entry fee is $20. Adult contestants are 18 years old and older, and their entry fee is $30. In each subclass, set the entry fee field to the correct value, and override the ToString() method to return a string that includes all the contestant data, including the age category and the entry fee. Modify the GreenvilleRevenue program so that it performs the following tasks: • The program prompts the user for the number of contestants in this year’s competition, which must be between 0 and 30. The program continues to prompt the user until a valid value is entered. • The program prompts the user for names, ages, and talent codes for the contestants entered. Along with the prompt for a talent code, display a list of valid categories. Based on the age entered for each contestant, create an object of the correct type (adult, teen, or child), and store it in an array of Contestant objects. • After data entry is complete, display the total expected revenue, which is the sum of the entry fees for the contestants. • After data entry is complete, display the valid talent categories and then continuously prompt the user for talent codes, and display all the data for all the contestants in each category. Display an appropriate message if the entered code is not a character or a valid code. (Please use the following code)
using System.IO;
using System;
class Contestant
{
public static string[] talent_values = { "S", "D", "M", "O"
};
public static string[] talent_names = { "Singing", "Dancing",
"Musical instrument", "Other" };
private string name;
private string talent_codes;
private string talent_name_values;
public string getName()
{
return name;
}
public void setName(string cname)
{
name = cname;
}
public string getTalentCode()
{
return talent_codes;
}
public void setTalentCode(string tcode)
{
bool check = false;
int i;
for (i = 0; i < talent_values.Length; i++)
{
if (talent_values[i] == tcode)
{
check = true;
break;
}
}
if (check)
{
talent_codes = tcode;
talent_name_values = talent_names[i];
}
else
talent_codes = "I";
}
public string getTalentNames()
{
return talent_name_values;
}
}
class Program
{
static void Main(string[] args)
{
int min = 0;
int max = 30;
int entFee = 25;
int this_year;
int last_year;
Console.WriteLine("Enter the number of contestants enter in last
year's competition 0-30: ");
last_year = cont_count();
Console.WriteLine("Enter the number of contestants entered in this year's competition 0-30: ");
this_year = cont_count();
array(this_year);
displayCompInfo(this_year, last_year, entFee);
}
public static int cont_count()
{
int min = 0;
int max = 30;
int entFee = 25;
int last = 0;
string b = Console.ReadLine();
int.TryParse(b, out last);
while (last < min || last > max)
{
Console.WriteLine("Your response is invalid, please enter a valid
between 0-30");
b = (Console.ReadLine());
int.TryParse(b, out last);
}
return last;
}
public static void array(int this_year)
{
//string[] contestants = new String[this_year];
//string[] talent = new String[this_year];
Contestant[] contestant = new Contestant[this_year];
string name;
for (int x = 0; x < this_year; x++)
{
Console.WriteLine("Please enter contestant " + (x + 1) + "'s
name");
name = Console.ReadLine();
contestant[x] = new Contestant();
contestant[x].setName(name);
bool correct = false;
while (!correct)
{
Console.WriteLine("\nPlease enter contestant " + (x + 1) + " 's
skill, 'S' for singing 'D' for dancing 'M' for " +
"musical instrument, or 'O' for other");
string type = Console.ReadLine().ToUpper();
for (int i = 0; i < Contestant.talent_values.Length;
i++)
{
if (Contestant.talent_values[i] == type)
{
contestant[x].setTalentCode(type);
correct = true;
}
}
if (!correct)
{
Console.WriteLine("Please enter a valid parameter");
}
}
}
talent(contestant);
}
public static void talent(Contestant[] contestant)
{
int singing_count = 0;
int dancing_count = 0;
int musical_ins_count = 0;
int other_count = 0;
string entry;
for (int x = 0; x < contestant.Length; x++)
{
if (contestant[x].getTalentCode() == "O")
{
other_count++;
}
else if (contestant[x].getTalentCode() == "S")
{
singing_count++;
}
else if (contestant[x].getTalentCode() == "D")
{
dancing_count++;
}
else if (contestant[x].getTalentCode() == "M")
{
musical_ins_count++;
}
}
Console.Clear();
Console.WriteLine("Number of contestants singing = " +
singing_count);
Console.WriteLine("Number of contestants dancing = " +
dancing_count);
Console.WriteLine("Number of contestants play musical instruments =
" + musical_ins_count);
Console.WriteLine("Number of contestants performing other talents =
" + other_count);
Console.WriteLine("Please enter a contestant talent code, ('S'
'D' 'M' 'O', to see a list of contestants with that skill or enter
'!' to exit.");
entry = Console.ReadLine().ToUpper();
while (entry != "!")
{
if (entry != "S" && entry != "D" && entry != "M"
&& entry != "O")
{
Console.WriteLine("Please try again: Enter a VALID skill code, 'S'
'D' 'M' 'O', to see a list of contestants with that skill or '!' to
exit.");
entry = Console.ReadLine().ToUpper();
if (entry == "!")
break;
}
for (int x = 0; x < contestant.Length; ++x)
{
if (entry == contestant[x].getTalentCode())
Console.WriteLine(" Contestant " + contestant[x].getName() + " -" +
contestant[x].getTalentNames());
}
Console.WriteLine("\nPlease enter a skill code, 'S' 'D' 'M' 'O', to
see a list of contestants with that skill or enter '!' to
exit");
entry = Console.ReadLine().ToUpper();
}
}
static void displayCompInfo(int this_year, int last_year, int
entFee)
{
if (this_year < last_year)
{
Console.WriteLine("A tighter race this year! Come out and cast your
vote!\n");
Console.WriteLine("The revenue expected for this year's competition
is {0:C}", (this_year * entFee));
}
}
}
//C# Code
using System.IO;
using System;
public class Contestant
{
public static string[] talent_values = { "S", "D", "M", "O"
};
public static string[] talent_names = { "Singing", "Dancing",
"Musical instrument", "Other" };
protected string name;
protected string talent_codes;
protected string talent_name_values;
protected double entry_fees;
public double getEntryFees()
{
return entry_fees;
}
public void setEntryFees(double e)
{
this.entry_fees = e;
}
public string getName()
{
return name;
}
public void setName(string cname)
{
name = cname;
}
public string getTalentCode()
{
return talent_codes;
}
public void setTalentCode(string tcode)
{
bool check = false;
int i;
for (i = 0; i < talent_values.Length; i++)
{
if (talent_values[i] == tcode)
{
check = true;
break;
}
}
if (check)
{
talent_codes = tcode;
talent_name_values = talent_names[i];
}
else
talent_codes = "I";
}
public string getTalentNames()
{
return talent_name_values;
}
public override string ToString()
{
return "Name: " + name + "\n Talent Code: " + talent_codes +
"\nTalent Name: " + talent_name_values +
"\nEntry Fees: " + entry_fees.ToString("C");
}
}
//Child classes
class ChildContestant : Contestant
{
public ChildContestant()
{
entry_fees = 15.0;
}
public override string ToString()
{
return base.ToString();
}
}
class TeenContestant :Contestant
{
public TeenContestant()
{
entry_fees = 20.0;
}
public override string ToString()
{
return base.ToString();
}
}
class AdultContestant : Contestant
{
public AdultContestant()
{
entry_fees = 30.0;
}
public override string ToString()
{
return base.ToString();
}
}
class Program
{
static void Main(string[] args)
{
int this_year;
int last_year;
//int entFee = 20;
// Console.WriteLine("Enter the number of contestants enter in last
year's competition 0-30: ");
// last_year = cont_count();
/**
* The program prompts the user for the number of contestants
* in this year’s competition, which must be between 0 and 30.
* The program
* continues to prompt the user until a valid value is
entered.
*/
Console.WriteLine("Enter the number of contestants entered in this
year's competition 0-30: ");
this_year = cont_count();
array(this_year);
// displayCompInfo(this_year, last_year, entFee);
}
public static int cont_count()
{
int min = 0;
int max = 30;
int entFee = 25;
int last = 0;
string b = Console.ReadLine();
int.TryParse(b, out last);
while (last < min || last > max)
{
Console.WriteLine("Your response is invalid, please enter a valid
between 0-30");
b = (Console.ReadLine());
int.TryParse(b, out last);
}
return last;
}
public static void array(int this_year)
{
/**
* The program prompts the user for names, ages, and talent
* codes for the contestants entered. Along with the prompt
for
* a talent code, display a list of valid categories. Based on
* the age entered for each contestant, create an object of
* the correct type (adult, teen, or child),
* and store it in an array of Contestant objects.
*/
Contestant[] contestant = new Contestant[this_year];
string name;
int age = 0;
for (int x = 0; x < this_year; x++)
{
Console.WriteLine("Please enter contestant " + (x + 1) + "'s
name");
name = Console.ReadLine();
Console.WriteLine("Please enter contestant " + (x + 1) + "'s
age");
age = int.Parse(Console.ReadLine());
if (age < 12)
contestant[x] = new ChildContestant();
else if (age > 12 && age <= 17)
contestant[x] = new TeenContestant();
else
contestant[x] = new AdultContestant();
contestant[x].setName(name);
bool correct = false;
while (!correct)
{
Console.WriteLine("\nPlease enter contestant " + (x + 1) + " 's
skill, 'S' for singing 'D' for dancing 'M' for " +
"musical instrument, or 'O' for other");
string type = Console.ReadLine().ToUpper();
for (int i = 0; i < Contestant.talent_values.Length;
i++)
{
if (Contestant.talent_values[i] == type)
{
contestant[x].setTalentCode(type);
correct = true;
}
}
if (!correct)
{
Console.WriteLine("Please enter a valid parameter");
}
}
}
talent(contestant);
displayContestantInfo(contestant);
displayRevenueInfo(contestant);
Console.ReadLine();
}
public static void talent(Contestant[] contestant)
{
int singing_count = 0;
int dancing_count = 0;
int musical_ins_count = 0;
int other_count = 0;
string entry;
for (int x = 0; x < contestant.Length; x++)
{
if (contestant[x].getTalentCode() == "O")
{
other_count++;
}
else if (contestant[x].getTalentCode() == "S")
{
singing_count++;
}
else if (contestant[x].getTalentCode() == "D")
{
dancing_count++;
}
else if (contestant[x].getTalentCode() == "M")
{
musical_ins_count++;
}
}
Console.Clear();
Console.WriteLine("Number of contestants singing = " +
singing_count);
Console.WriteLine("Number of contestants dancing = " +
dancing_count);
Console.WriteLine("Number of contestants play musical instruments =
" + musical_ins_count);
Console.WriteLine("Number of contestants performing other talents =
" + other_count);
Console.WriteLine("Please enter a contestant talent code, ('S'
'D' 'M' 'O', to see a list of contestants with that skill or enter
'!' to exit.");
entry = Console.ReadLine().ToUpper();
while (entry != "!")
{
if (entry != "S" && entry != "D" && entry != "M"
&& entry != "O")
{
Console.WriteLine("Please try again: Enter a VALID skill code, 'S'
'D' 'M' 'O', to see a list of contestants with that skill or '!' to
exit.");
entry = Console.ReadLine().ToUpper();
if (entry == "!")
break;
}
for (int x = 0; x < contestant.Length; ++x)
{
if (entry == contestant[x].getTalentCode())
Console.WriteLine(" Contestant " + contestant[x].getName() + " -" +
contestant[x].getTalentNames());
}
Console.WriteLine("\nPlease enter a skill code, 'S' 'D' 'M' 'O', to
see a list of contestants with that skill or enter '!' to
exit");
entry = Console.ReadLine().ToUpper();
}
}
/**
* display Contestant Info
*/
static void displayContestantInfo(Contestant[] contestants)
{
Console.WriteLine("Contestants's Info: ");
foreach(Contestant c in contestants)
{
Console.WriteLine(c);
}
}
/**
* display the total expected revenue, which is the sum of the entry
fees for the contestants.
*/
static void displayRevenueInfo(Contestant[] contestants)
{
double sum = 0.0;
foreach(Contestant c in contestants)
{
sum += c.getEntryFees();
}
Console.WriteLine("Expected Revenue: " + sum.ToString("C"));
}
static void displayCompInfo(int this_year, int last_year, int
entFee)
{
if (this_year < last_year)
{
Console.WriteLine("A tighter race this year! Come out and cast your
vote!\n");
Console.WriteLine("The revenue expected for this year's competition
is {0:C}", (this_year * entFee));
}
}
}
//output
//If you need any help regarding this solution ........... please leave a comment ......... thanks
Get Answers For Free
Most questions answered within 1 hours.