In: Computer Science
Modify the GreenvilleRevenue program so that it uses the Contestant class and performs the following tasks: The program prompts the user for the number of contestants in this year’s competition; the number must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The expected revenue is calculated and displayed. The revenue is $25 per contestant. For example if there were 3 contestants, the expected revenue would be displayed as: Revenue expected this year is $75.00 The program prompts the user for names and talent codes for each contestant entered. Along with the prompt for a talent code, display a list of the valid categories. The categories should be displayed in the following format: The types of talent are: S Singing D Dancing M Musical instrument O Other After data entry is complete, the program displays the valid talent categories and then continuously prompts the user for talent codes and displays the names of all contestants in the category. Appropriate messages are displayed if the entered code is not a character or a valid code.
beginning of c# code:
using System;
using static System.Console;
using System.Globalization;
class GreenvilleRevenue
{
static void Main()
{
// Your code here
}
}
/*
* C sharp program that prompts users to enter the number of
participants.
* Then prompt for the names and talent codes from the user. If the
user enters an invalid
* talent codes then reprompt for valid talent codes. Then display
the names in
* Each category on the C# console window.
*/
//GreenvilleRevenue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GreenvilleRevenue
{
class GreenvilleRevenue
{
static void Main(string[] args)
{
//Set constants and variabel names
const int COST_PER_CONTESTANT = 25;
int numParticipants = 0;
int revenue=0;
String talentCode = "";
//do-while loop
do
{
Console.Write("Enter # of participants : ");
//Read number of participants
int.TryParse(Console.ReadLine(), out numParticipants);
//Check valid range of partcipants
if (numParticipants < 0 || numParticipants > 30)
Console.WriteLine("Invalid number of particpant.");
} while (numParticipants < 0 || numParticipants > 30);
//Calculate the total revenue
revenue =numParticipants*COST_PER_CONTESTANT ;
Console.WriteLine("Revenue expected this year is ${0}",
revenue.ToString("N2"));
//Create arrays of number of participants for names and talent
codes
String[] names = new String[numParticipants];
String[] tcodes = new String[numParticipants];
//Loop to enter names and category codes
for (int index = 0; index < numParticipants ; index++)
{
//Read name of the particpant
Console.Write("Enter name of particpant : ");
//Read name
names[index] = Console.ReadLine();
//do-while loop
do
{
//Calling method, displayTalentCodes
displayTalentCodes();
talentCode = Console.ReadLine();
if (talentCode != "S" && talentCode != "D"
&& talentCode != "M" && talentCode != "O")
Console.WriteLine("Invalid talent code");
} while (talentCode!="S" && talentCode !="D"
&& talentCode !="M" &&talentCode != "O");
//Set talentCode to the tcodes at index
tcodes[index] = talentCode;
}//end of the for loop
Console.WriteLine("Singing category particpants :");
for (int index = 0; index < numParticipants; index++)
{
//Print Singing category names
if (tcodes[index] == "S")
Console.WriteLine("{0}", names[index]);
}
Console.WriteLine("\nDance category particpants :");
for (int index = 0; index < numParticipants; index++)
{
//Print Dance category names
if (tcodes[index] == "D")
Console.WriteLine("{0}", names[index]);
}
Console.WriteLine("\nMusic category particpants :");
for (int index = 0; index < numParticipants; index++)
{
//Print Music category names
if (tcodes[index] == "M")
Console.WriteLine("{0}", names[index]);
}
Console.WriteLine("\nOther category particpants :");
//Print Other category names
for (int index = 0; index < numParticipants; index++)
{
if (tcodes[index] == "O")
Console.WriteLine("{0}", names[index]);
}
Console.ReadKey();
}
/*Method, displayTalentCodes that display a menu of talent
codes*/
public static void displayTalentCodes()
{
Console.WriteLine("S Singing");
Console.WriteLine("D Dancing");
Console.WriteLine("M Musical instrument");
Console.WriteLine("O Other");
} //end of the method, displayTalentCodes
} //end of the class,GreenvilleRevenue
}//end of the namespace
Sample output screenshot: