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.
using System;
namespace GreenvilleRevenue { class Contestant { public static string[] talentCodes = { "S", "D", "M", "O" }; public static string[] talentDescr = { "Singer", "Dancer", "Musician", "Other" }; private string name; private string talentCode; private string talentDesc;
public string getContestantName() { return name; }
public void setName(string contestantName) { name = contestantName; }
public string getTalentCode() { return talentCode; }
public void setTalentCode(string valid) { bool exists = false; int i; for (i = 0; i < talentCodes.Length; i++) { if (talentCodes[i] == valid) { exists = true; break; } }
if (exists) { talentCode = valid; talentDesc = talentDescr[i]; } else talentCode = "I"; } public string getTalentDescr() { return talentDesc; } } class GreenvilleRevenue { static void Main(string[] args) { int thisYearsContestants; int lastYearsContestants; Console.WriteLine("Please enter the number of contestants for last year.>>"); lastYearsContestants = contestant(); Console.WriteLine("Please enter the number of contestants for this year.>>"); thisYearsContestants = contestant(); array(thisYearsContestants); compare(thisYearsContestants, lastYearsContestants);
}
public static int contestant() { int last = 0; string b; b = (Console.ReadLine()); int.TryParse(b, out last); while (last > 30 || last < 0) { Console.WriteLine("Valid values for the contestant field are Integers between 0 and 30. Please try again.>>"); b = (Console.ReadLine()); int.TryParse(b, out last); } return last; }
public static void array(int thisyear) { //string[] contestant = new string[thisyear]; //string[] skill = new string[thisyear]; Contestant[] contestant = new Contestant[thisyear]; string name;
for (int x = 0; x < thisyear; ++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 single digit talent code; Talent codes are (S)inger, (D)ancer, (M)usician, or (O)ther.>>"); string type = Console.ReadLine().ToUpper();
for (int i = 0; i < Contestant.talentCodes.Length; i++) { if (Contestant.talentCodes[i] == type) { contestant[x].setTalentCode(type); correct = true; } } if (!correct) { Console.WriteLine("That was not a valid talent code, Please try again.>>"); }
}
}
talent(contestant); }
public static void talent(Contestant[] contestant) { int dancer = 0; int musician = 0; int singer = 0; int other = 0; string input; for (int x = 0; x < contestant.Length; ++x) {
if (contestant[x].getTalentCode() == "O") { ++other; } else if (contestant[x].getTalentCode() == "S") { ++singer; } else if (contestant[x].getTalentCode() == "D") { ++dancer; } else if (contestant[x].getTalentCode() == "M") { ++musician; }
} Console.Clear(); Console.WriteLine("Currently signed up, we have..."); Console.WriteLine("{0} Dancers", dancer); Console.WriteLine("{0} Singers", singer); Console.WriteLine("{0} Musicians", musician); Console.WriteLine("{0} Everything else!", other); Console.WriteLine("To see a list of all contestants with a specific talent, Please enter a talent code. Talent codes are(S)inger, (D)ancer, (M)usician, (O)ther; altenatively, you may type (E) to exit.>>"); input = Console.ReadLine().ToUpper(); while (input != "E") { if (input != "S" && input != "D" && input != "M" && input != "O") { Console.WriteLine("***Invalid Entry*** Talent codes are(S)inger, (D)ancer, (M)usician, (O)ther; altenatively, you may type (E) to exit.>>"); input = Console.ReadLine().ToUpper(); if (input == "!") break; } for (int x = 0; x < contestant.Length; ++x) { if (input == contestant[x].getTalentCode()) Console.WriteLine(" Contestant: '" + contestant[x].getContestantName() + "' Talent: " + contestant[x].getTalentDescr()); } Console.WriteLine("To see a list of all contestants with a specific talent, Please enter a talent code. Talent codes are(S)inger, (D)ancer, (M)usician, (O)ther; altenatively, you may type (E) to exit.>>"); input = Console.ReadLine().ToUpper(); } }
public static void compare(int thisYearsContestants, int lastYearsContestants) {
if (thisYearsContestants > lastYearsContestants * 2) { Console.WriteLine("The competition is more than twice as big this year!"); Console.WriteLine("The revenue expected for this year's competition is {0:C}", (thisYearsContestants * 25)); } else
if (thisYearsContestants > lastYearsContestants && thisYearsContestants <= (lastYearsContestants * 2)) { Console.WriteLine("The competition is bigger than ever!"); Console.WriteLine("The revenue expected for this year's competition is {0:C}", (thisYearsContestants * 25)); } else
if (thisYearsContestants < lastYearsContestants) { 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}", (thisYearsContestants * 25)); } } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
