Greenville MidTerm Grade A

[code language=”csharp”] using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

/// <summary>
/// # # # # # # # # # # #
/// # Mark Hesser #
/// # Jan 30, 18 #
/// # GreenvilleRevenue #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// # Instructions: #
/// # 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 whether this year’s competition has #
/// # more contestants than last year’s. #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// </summary>
namespace GreenvilleRevenue
{
class Revenue
{
#region Static Declarations
static string[] contestants;
static char[] codes;
#endregion

static void Main(string[] args)
{
#region Declarations
bool quit = false;
int lastYear = 0, thisYear = 0;
double lastRevenue, thisRevenue;
string message = "";
#endregion

Title = "Greenville County Fair";

while (!quit)
{
Clear();

WriteLine(" Please enter the number of contestants that are going to be " +
"\n in this year’s competition and last year’s competition\n");

InputNumContestants(ref lastYear, ref thisYear);
InputContestantNames(thisYear);
lastRevenue = ComputeRevenue(lastYear);
thisRevenue = ComputeRevenue(thisYear);

Clear();
message = CalculateResponse(lastYear, thisYear);

WriteLine(" {0}\n", message);

WriteLine(" Last Year, {0} Contestants generated {1:C} of revenue. ", lastYear, lastRevenue);
WriteLine(" This Year, {0} Contestants will generate {1:C} of revenue. ", thisYear, thisRevenue);

Quit(ref quit);
}
}

/// <summary>
/// Accepts integars for last year’s and this year’s contestants
/// </summary>
/// <param name="lastYear"></param>
/// <param name="thisYear"></param>
static void InputNumContestants(ref int lastYear, ref int thisYear)
{
bool validInput1 = false, validInput2 = false;

while (!validInput1)
{
Write(" Last Year: ");
int.TryParse(ReadLine(), out lastYear);

if (lastYear >= 0 && lastYear <= 30)
validInput1 = true;
else
WriteLine(" That is not a valid entry… Please Try Again\n");
}
while (!validInput2)
{
Write(" This Year: ");
int.TryParse(ReadLine(), out thisYear);

if (thisYear >= 0 && thisYear <= 30)
validInput2 = true;
else
WriteLine(" That is not a valid entry… Please Try Again!\n");
}
}

static void InputContestantNames(int thisYear)
{
contestants = new string[thisYear];
codes = new char[thisYear];
char[] validCodes = "SDMO".ToCharArray();
bool isValidCode = false;

WriteLine("\n Please Enter each Contestant’s name \n");

for (int i = 0; i < contestants.Length; i++)
{
Write(" Contestant {0}: ", i + 1);
contestants[i] = ReadLine();
}

WriteLine("\n Please Enter each contestant’s talent code." +
"\n S for singing, D for dancing, M for playing a musical instrument, or O for other.\n");
for (int i = 0; i < codes.Length; i++)
{
isValidCode = false;
do
{
Write(" {0}’s Talent Code: ", contestants[i]);
Char.TryParse(ReadLine(), out codes[i]);
codes[i] = Char.ToUpper(codes[i]);

if (validCodes.Contains(codes[i]))
isValidCode = true;
else
WriteLine(" That is not a Valid Code… Please Try Again!\n");
} while (!isValidCode);

WriteLine();
}
}

/// <summary>
///
/// </summary>
/// <param name="contestants"></param>
/// <returns></returns>
static double ComputeRevenue(int contestants)
{
const double entranceFee = 25;
double revenue = entranceFee * contestants;
return revenue;
}

static string CalculateResponse(int lastYear, int thisYear)
{
string message = "";

if (thisYear > lastYear && !(thisYear >= (lastYear * 2)))
{
message = "The competition is bigger than ever!";
}
else if (thisYear >= (lastYear * 2))
{
message = "The competition is more than twice as big this year!";
}
else if (thisYear < lastYear)
{
message = "A tighter race this year! Come out and cast your vote!";
}
else
message = "";

return message;
}

/// <summary>
/// Asks the user if they would like to continue.
/// </summary>
static void Quit(ref bool quit)
{
ConsoleKeyInfo kb;
//Asks the user
Write("\n Would you like to Continue? (y/n) ");
#region Quit?
kb = ReadKey(); //Listens for Key
if (kb.Key == ConsoleKey.N) //Ends the Program
{
quit = true;
}
else if (kb.Key == ConsoleKey.Y)
{
quit = false;
}
else //Tells the User they are stupid and then Quits the program
{
WriteLine("\n You didn’t hit Y or N. " +
"\n I’m going to assume you said No. " +
"\n Press Any Key Quit…\a");
ReadKey();
quit = true; //Ends Program
}
#endregion
}
}
}
[/code]