Question
In C# I am asked once again to modify my code to the following: In Chapter 6, you continued to modify the GreenvilleRevenue program. Now,
In C# I am asked once again to modify my code to the following:
In Chapter 6, you continued to modify the GreenvilleRevenue program. Now, modify the program so that the major functions appear in the following individual methods:
A method that gets and returns a valid number of contestants and is called twice once for last years number of contestants and once for this years value
A method that accepts the number of contestants this year and last year and displays one of the three messages that describes the relationship between the two contestant values
A method that fills the array of competitors and their talent codes
A method that continuously prompts for talent codes and displays contestants with the corresponding talent until a sentinel value is entered
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 GreenvilleRevenue { 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 Singin '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 is " + 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started