Question: Is there something wrong with this code? Every time I run chucks on it, it comes back saying that there is an unexpected output Jill.

Is there something wrong with this code?

Every time I run chucks on it, it comes back saying that there is an unexpected output "Jill".

using System;

using static System.Console;

using System.Globalization;

// Define the Contestant class

class Contestant

{

// Declare public static arrays to hold talent codes and descriptions

public static char[] talentCodes = { 'S', 'D', 'M', 'O' };

public static string[] talentStrings = { "Singing", "Dancing", "Musical instrument", "Other" };

// Declare a property Name to hold a contestant's name

public string Name { get; set; }

// Declare fields for talent code and description

private char talentCode;

public char TalentCode

{

set

{

// Assign a code only if it is valid

if (Array.IndexOf(talentCodes, value) != -1)

{

talentCode = value;

}

else

{

// Otherwise, assign I for Invalid

talentCode = 'I';

}

}

get

{

return talentCode;

}

}

// Declare a read-only property Talent that holds the talent description

public string Talent

{

get

{

// Assign a value to the talent description when the code is set

return talentStrings[Array.IndexOf(talentCodes, talentCode)];

}

}

}

class GreenvilleRevenue

{

static void Main()

{

// Prompt the user for the number of contestants in this year's competition

int numContestants;

do

{

Write("Enter the number of contestants in this year's competition (0 to 30): ");

} while (!int.TryParse(ReadLine(), out numContestants) || numContestants < 0 || numContestants > 30);

// Calculate the expected revenue

double revenue = 25 * numContestants;

// Display the expected revenue

WriteLine("Revenue expected this year is {0}", revenue.ToString("C", CultureInfo.GetCultureInfo("en-US")));

// Declare an array to hold contestants

Contestant[] contestants = new Contestant[numContestants];

// Prompt the user for names and talent codes for each contestant entered

for (int i = 0; i < numContestants; i++)

{

// Prompt the user for a name

Write("Enter the name of contestant {0}: ", i + 1);

contestants[i] = new Contestant { Name = ReadLine() };

// Display a list of the valid categories

WriteLine("The types of talent are:");

WriteLine("S\tSinging");

WriteLine("D\tDancing");

WriteLine("M\tMusical instrument");

WriteLine("O\tOther");

// Prompt the user for a talent code

char code;

do

{

Write("Talent codes are Joey {0}: ", contestants[i].Name);

} while (!char.TryParse(ReadLine(), out code));

contestants[i].TalentCode = code;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!