Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is wrong with this code: using System; using System.Globalization; namespace GreenvilleRevenue { class Program { static void Main(string[] args) { const double CHILD_FEE =

What is wrong with this code:

using System;

using System.Globalization;

namespace GreenvilleRevenue

{

class Program

{

static void Main(string[] args)

{

const double CHILD_FEE = 15.0;

const double TEEN_FEE = 20.0;

const double ADULT_FEE = 30.0;

Console.WriteLine("Enter the number of contestants (0-30): ");

int numContestants = int.Parse(Console.ReadLine());

Contestant[] contestants = new Contestant[numContestants];

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

{

Console.WriteLine("Enter data for contestant #{0}:", i + 1);

Console.Write("Name: ");

string name = Console.ReadLine();

Console.Write("Age: ");

int age = int.Parse(Console.ReadLine());

Console.WriteLine("Talent codes are: S Singing D Dancing M Musical instrument O Other");

Console.Write("Talent code: ");

char talentCode = char.Parse(Console.ReadLine().ToUpper());

if (age <= 12)

{

contestants[i] = new ChildContestant(name, talentCode);

}

else if (age >= 13 && age <= 17)

{

contestants[i] = new TeenContestant(name, talentCode);

}

else

{

contestants[i] = new AdultContestant(name, talentCode);

}

}

double totalRevenue = 0.0;

foreach (Contestant c in contestants)

{

totalRevenue += c.Fee;

}

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

Console.WriteLine("Valid talent categories are: S Singing D Dancing M Musical instrument O Other");

while (true)

{

Console.Write(" Enter a talent code (0 to exit): ");

char code = char.Parse(Console.ReadLine().ToUpper());

if (code == '0')

{

break;

}

bool found = false;

foreach (Contestant c in contestants)

{

if (c.TalentCode == code)

{

Console.WriteLine(c.ToString());

found = true;

}

}

if (!found)

{

Console.WriteLine("Invalid code entered: {0}", code);

}

}

}

}

public class Contestant

{

public string Name { get; set; }

public char TalentCode { get; set; }

public double Fee { get; set; }

public Contestant(string name, char talentCode, double fee)

{

Name = name;

TalentCode = talentCode;

Fee = fee;

}

public override string ToString()

{

return string.Format("{0} Contestant {1} {2} Fee {3}", AgeCategory(), Name, TalentCode, Fee.ToString("C", CultureInfo.GetCultureInfo("en-US")));

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions