Question

Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now...

Use a C#

In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics:

  • The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively.
  • The class contains an auto-implemented property Name that holds a contestant’s name.
  • The class contains fields for a talent code (talentCode) and description (talent). The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. The talent description is a read-only property that is assigned a value when the code is set.

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.

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("\nThe types of talent are:");
for(x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]);
Write("\nEnter 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("\nEnter 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("\nEnter a talent type or {0} to quit >> ", QUIT);
}
else
{
WriteLine("\nContestants 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("\nEnter a talent type or {0} to quit >> ", QUIT);
}
}
}
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C# code

using System;
using static System.Console;

namespace Greenville
{
class Contestant
{
public static char[] talentCodes = { 'S', 'D', 'M', 'O' };
public static string[] talentCodesStrings = { "Singing", "Dancing", "Musical instrument", "Other" };
/**
* an auto-implemented property Name that holds a contestant’s name.
*/
public string Name
{
get;
set;
}
private char talentCode; //talent code
private string talent;//description
public char TalentCode
{
get
{
return talentCode;
}
set
{
switch (value)
{
case 'S':
talentCode = value;
talent = talentCodesStrings[0];
break;
case 'D':
talentCode = value;
talent = talentCodesStrings[1];
break;
case 'M':
talentCode = value;
talent = talentCodesStrings[2];
break;
case 'O':
talentCode = value;
talent = talentCodesStrings[3];
break;
default:
talentCode = 'I';
talent = "Invalid";
break;
}
}
}
public string Talent
{
get
{
return talent;
}
}
}
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;
Contestant[] contestants = new Contestant[MAX_CONTESTANTS];
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, contestants, counts);
getLists(numThisYear,contestants, 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,Contestant[] contestants, int[] counts)
{
int x = 0;
bool isValid;
while (x < numThisYear)
{
Contestant contestant = new Contestant();
Write("Enter contestant name >> ");
contestant.Name = ReadLine();
contestants[x] = contestant;
WriteLine("Talent codes are:");
for (int y = 0; y < Contestant.talentCodes.Length; ++y)
WriteLine(" {0} {1}", Contestant. talentCodes[y], Contestant.talentCodesStrings[y]);
Write(" Enter talent code >> ");
isValid = false;
while (!isValid)
{
char talent;
if (!char.TryParse(ReadLine(), out talent))
{
WriteLine("Invalid format - entry must be a single character");
}
else
for (int z = 0; z < Contestant.talentCodes.Length; ++z)
{
if (talent == Contestant.talentCodes[z])
{
contestant.TalentCode = talent;
isValid = true;
++counts[z];
}
}
if (!isValid)
{
WriteLine("That is not a valid code");
Write(" Enter talent code >> ");
}
}
++x;
}
}
public static void getLists(int numThisYear,Contestant[] contestants, int[] counts)
{
int x;
char QUIT = 'Z';
char option;
bool isValid;
int pos = 0;
bool found;
WriteLine("\nThe types of talent are:");
for (x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", Contestant.talentCodesStrings[x], counts[x]);
Write("\nEnter 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("\nEnter a talent type or {0} to quit >> ", QUIT);
}
else
{
if (option == QUIT)
isValid = true;
else
{
for (int z = 0; z < Contestant.talentCodes.Length; ++z)
{
if (option == Contestant.talentCodes[z])
{
isValid = true;
pos = z;
}
}
if (!isValid)
{
WriteLine("{0} is not a valid code", option);
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
}
else
{
WriteLine("\nContestants with talent {0} are:", Contestant.talentCodesStrings[pos]);
found = false;
for (x = 0; x < numThisYear; ++x)
{
if (contestants[x].TalentCode == option)
{
WriteLine(contestants[x].Name);
found = true;
}
}
if (!found)
WriteLine("No contestants had talent {0}", Contestant.talentCodesStrings[pos]);
isValid = false;
Write("\nEnter a talent type or {0} to quit >> ", QUIT);
}
}
}
}
}
}
}

//Output

//If you need any help regarding this solution ........... please leave a comment ........ thanks

Add a comment
Know the answer?
Add Answer to:
Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the...

    In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the user for contestant data for this year’s Greenville Idol competition. Now, save all the entered data to a Greenville.ser file that is closed when data entry is complete and then reopened and read in, allowing the user to view lists of contestants with requested talent types. The program should output the name of the contestant, the talent, and the fee. using System; using static...

  • In Chapter 1, you created two programs to display the motto for the Greenville Idol competition...

    In Chapter 1, you created two programs to display the motto for the Greenville Idol competition that is held each summer during the Greenville County Fair. Now write a program named GreenvilleRevenue that prompts a user for the number of contestants entered in last year’s competition and in this year’s competition. Display all the input data. Compute and display the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. Also display a statement that indicates...

  • Case Program 10 – 1: Part 1: Previously, you created a Contestant class for the Greenville Idol c...

    Case Program 10 – 1: Part 1: Previously, 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 Fee that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three...

  • In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now,...

    In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format...

  • In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now,...

    In Chapter 5, you wrote a HomeSales application for three salespeople: Danielle, Edward, and Francis. Now, using the code you wrote in Chapter 5, Programming Exercise 5, modify the program to use arrays to store the salesperson names, allowed initials, and accumulated sales values. In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format...

  • In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a...

    In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4. Now, modify the program so that the user must enter a month value from 1 through 12....

  • In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now...

    In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now modify the Rental and RentalDemo classes as follows: Modify the Rental class to include an integer field that holds an equipment type. Add a final String array that holds names of the types of equipment that Sammy's rents—personal watercraft, pontoon boat, rowboat, canoe, kayak, beach chair, umbrella, and other. Include get and set methods for the integer equipment type field. If the argument passed...

  • Modify the Triangle class (from previous code, will post under this) to throw an exception in...

    Modify the Triangle class (from previous code, will post under this) to throw an exception in the constructor and set routines if the triangle is not valid (i.e., does not satisfy the triangle inequality). Modify the main routine to prompt the user for the sides of the triangle and to catch the exception and re-prompt the user for valid triangle sides. In addition, for any valid triangle supply a method to compute and display the area of the triangle using...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • With a Scanner object created as follows, what method do you use to read an int...

    With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT