Question
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestants name, talent code, and talent description. The
In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes a contestants 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 years 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(" Please 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(" Please 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! "); Console.WriteLine("The revenue expected for this year's competition is {0:C}", (this_year * entFee)); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started