Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C# I am asked to modify my exsisting code, to meet these requirments: Modify the GreenvilleRevenue program created in the previous chapter so that

In C# I am asked to modify my exsisting code, to meet these requirments:

Modify the GreenvilleRevenue program created in the previous chapter so that it performs the following tasks: The program prompts the user for the number of contestants in this years competition; the number must be between 0 and 30. Use exception-handling techniques to ensure a valid value. The program prompts the user for talent codes. Use exception-handling techniques to ensure a valid code. After data entry is complete, the program prompts the user for codes so the user can view lists of appropriate contestants. Use exception-handling techniques for the code verification.

The code I have so far is as follows:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace GreenvilleRevenue1 { class Contestant { public static string[] talentCodes = { "S", "D", "M", "O" }; public static string[] talentDescr = { "Singing", "Dancing", "Musical instrument", "Other" };

private string name; private string skillCode; private string skillDescr;

public string getName() { return name; }

public void setName(string cname) { name = cname; }

public string getSkillCode() { return skillCode; }

public void setSkillCode(string scode) { bool found = false; int i; for (i = 0; i < talentCodes.Length; i++) { if (talentCodes[i] == scode) { found = true; break; } }

if (found) { skillCode = scode; skillDescr = talentDescr[i]; } else skillCode = "I"; }

public string getSkillDescr() { return skillDescr; }

} class Program { static void Main(string[] args) { int contCurr; int contLast; Console.WriteLine("Please enter the number of contestants from last years contest"); contLast = cont(); Console.WriteLine(" Please enter the number of contestants from this years contest"); contCurr = cont(); array(contCurr); comp(contCurr, contLast);

}

public static int cont() { int last = 0; string b; b = (Console.ReadLine()); int.TryParse(b, out last); while (last > 30 || last < 0) { Console.WriteLine(" You have entered and invalid response, please enter a valid number between 0 and 30."); b = (Console.ReadLine()); int.TryParse(b, out last); } return last; }

public static void array(int thisyear) { //string[] contestant = new string[thisyear]; //string[] skill = new string[thisyear]; Contestant[] contestant = new Contestant[thisyear]; string name;

for (int x = 0; x < thisyear; ++x) { Console.WriteLine(" Please enter contestant " + (x + 1) + "'s name"); name = Console.ReadLine(); contestant[x] = new Contestant(); contestant[x].setName(name); bool correct = false; while (!correct) { Console.WriteLine(" Please enter contestant " + (x + 1) + " 's skill, 'S' for Singing 'D' for Dancing 'M' for " + "Musical Instrument 'O' for Other"); string type = Console.ReadLine().ToUpper();

for (int i = 0; i < Contestant.talentCodes.Length; i++) { if (Contestant.talentCodes[i] == type) { contestant[x].setSkillCode(type); correct = true; } } if (!correct) { Console.WriteLine(" Please enter a valid parameter"); }

}

}

talent(contestant); }

public static void talent(Contestant[] contestant) { int dance = 0; int instrument = 0; int sing = 0; int other = 0; string entry; for (int x = 0; x < contestant.Length; ++x) {

if (contestant[x].getSkillCode() == "O") { ++other; } else if (contestant[x].getSkillCode() == "S") { ++sing; } else if (contestant[x].getSkillCode() == "D") { ++dance; } else if (contestant[x].getSkillCode() == "M") { ++instrument; }

} Console.Clear(); Console.WriteLine("There are:"); Console.WriteLine("{0} Dancers", dance); Console.WriteLine("{0} Singers", sing); Console.WriteLine("{0} Musicians", instrument); Console.WriteLine("{0} Contestant(s) with other skills", other); Console.WriteLine(" Please enter a skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or enter '!' to exit"); entry = Console.ReadLine().ToUpper(); while (entry != "!") { if (entry != "S" && entry != "D" && entry != "M" && entry != "O") { Console.WriteLine(" Please try again: Enter a VALID skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or '!' to exit"); entry = Console.ReadLine().ToUpper(); if (entry == "!") break; } for (int x = 0; x < contestant.Length; ++x) { if (entry == contestant[x].getSkillCode()) Console.WriteLine(" Contestant " + contestant[x].getName() + " skill " + contestant[x].getSkillDescr()); } Console.WriteLine(" Please enter a skill code 'S' 'D' 'M' 'O' to see a list of contestants with that skill or enter '!' to exit"); entry = Console.ReadLine().ToUpper(); } }

public static void comp(int contCurr, int contLast) {

if (contCurr > contLast * 2) { Console.WriteLine(" The competition is more than twice as big this year! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } else

if (contCurr > contLast && contCurr <= (contLast * 2)) { Console.WriteLine(" The competition is bigger than ever! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } else

if (contCurr < contLast) { Console.WriteLine(" A tighter race this year! Come out and cast your vote! "); Console.WriteLine(" The revenue expected for this year's competition is {0:C}", (contCurr * 25)); } } } }

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