Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I use MindTap and have tried all the answers on here and nothing... please don't use Visual Studios. If you have MindTap please help by

I use MindTap and have tried all the answers on here and nothing... please don't use Visual Studios. If you have MindTap please help by posing code! Thanks!

Problem:

Previously, 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.

Now, modify your program so the Contestant class contains the field Fee 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. For example, the output from ToString() should be displayed in the following format:

Child Contestant Joeph S Fee $15.00 Teen Contestant Sara M Fee $20.00 Adult Contestant Joy D Fee $30.00

Step 2:

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 the name, talent code, and age for each contestant. 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. Talent code categories should be displayed in the following format:
    Talent codes are: S Singing D Dancing M Musical instrument O Other
  • After data entry is complete, display the total expected revenue, which is the sum of the entry fees for the contestants. The total expected revenue should be displayed in the following format:
    Revenue expected this year is $65.00
  • 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 (using the ToString method for each contestant). Display an appropriate message if the entered code is not a character or a valid code.

Code:

using static System.Console; class GreenvilleRevenue { static void Main() { const int ENTRANCE_FEE = 25; const int MIN_CONTESTANTS = 0; const int MAX_CONTESTANTS = 30; int numThisYear; int numLastYear; int revenue; 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}; numLastYear = getContestantNumber("last", MIN_CONTESTANTS, MAX_CONTESTANTS); numThisYear = getContestantNumber("this", MIN_CONTESTANTS, MAX_CONTESTANTS); revenue = numThisYear * ENTRANCE_FEE; WriteLine("Last year's competition had {0} contestants, and this year's has {1} contestants", numLastYear, numThisYear); WriteLine("Revenue expected this year is {0}", revenue.ToString("C")); displayRelationship(numThisYear, numLastYear); getContestantData(numThisYear, names, talents, talentCodes, talentCodesStrings, counts); getLists(numThisYear, talentCodes, talentCodesStrings, names, talents, counts); } public static int getContestantNumber(string when, int min, int max) { string entryString; int num = max + 1; Write("Enter number of contestants {0} year >> ", when); entryString = ReadLine(); while(num < min || num > max) { if(!int.TryParse(entryString, out num)) { WriteLine("Format invalid"); num = max + 1; Write("Enter number of contestants {0} year >> ", when); entryString = ReadLine(); } else { if(num < min || num > max) { WriteLine("Number must be between {0} and {1}", min, max); num = max + 1; Write("Enter number of contestants {0} year >> ", when); entryString = ReadLine(); } } } return num; } public static void displayRelationship(int numThisYear, int numLastYear) { if(numThisYear > 2 * numLastYear) WriteLine("The competition is more than twice as big this year!"); else if(numThisYear > numLastYear) WriteLine("The competition is bigger than ever!"); else 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) { int x = 0; bool isValid; while(x < numThisYear) { Write("Enter contestant name >> "); names[x] = ReadLine(); WriteLine("Talent codes are:"); for(int y = 0; y < talentCodes.Length; ++y) WriteLine(" {0} {1}", talentCodes[y], talentCodesStrings[y]); Write(" Enter talent code >> "); isValid = false; while(!isValid) { if(!char.TryParse(ReadLine(), out talents[x])) { WriteLine("Invalid format - entry must be a single character"); } else for(int z = 0; z < talentCodes.Length; ++z) { if(talents[x] == talentCodes[z]) { isValid = true; ++counts[z]; } } if(!isValid) { WriteLine("That is not a valid code"); Write(" Enter talent code >> "); } } ++x; } } public static void getLists(int numThisYear, char[] talentCodes, string[] talentCodesStrings, string[] names, char[] talents, int[] counts) { int x; char QUIT = 'Z'; char option; bool isValid; int pos = 0; bool found; WriteLine(" The types of talent are:"); for(x = 0; x < counts.Length; ++x) WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]); Write(" Enter a talent type or {0} to quit >> ", QUIT); isValid = false; while(!isValid) { if(!char.TryParse(ReadLine(), out option)) { isValid = false; WriteLine("Invalid format - entry must be a single character"); Write(" Enter a talent type or {0} to quit >> ", QUIT); } else { if(option == QUIT) isValid = true; else { for(int z = 0; z < talentCodes.Length; ++z) { if(option == talentCodes[z]) { isValid = true; pos = z; } } if(!isValid) { WriteLine("{0} is not a valid code", option); Write(" Enter a talent type or {0} to quit >> ", QUIT); } else { WriteLine(" Contestants with talent {0} are:", talentCodesStrings[pos]); found = false; for(x = 0; x < numThisYear; ++x) { if(talents[x] == option) { WriteLine(names[x]); found = true; } } if(!found) WriteLine("No contestants had talent {0}", talentCodesStrings[pos]); isValid = false; Write(" Enter a talent type or {0} to quit >> ", QUIT); } } } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions