Question: Can someone help me with the UML for this code.......... I am a little confused on it???? Analyze, Design, Code, Test (PDLC) a solution from
Can someone help me with the UML for this code.......... I am a little confused on it????
Analyze, Design, Code, Test (PDLC) a solution from conception to implementation. Instructions: design and code an object-oriented solution for the following, you may design either a console application or a GUI application. Design a program named ContestantDemo that contains a contestant class that has public static arrays that hold talent codes and descriptions. The talent descriptions are Singing, Dancing, Musical Instrument, and Other. The talent codes are S, D, M, and O. The class should contain fields for the contestants name. The class should contain fields for a talent code and description. The set accessor for the code assigns a code only if it is valid. Otherwise, it assigns I for Invalid. You should create a method that performs this task. The talent description is a read-only property that is assigned a value when the code is set. Include a field that holds the entry fee for each category and get and set accessors. Extend the Contestant class to create three subclasses, ChildContestant, TeenContestant, and AdultContestant. Child contestants should be 12 and younger and their fee is $15, Teen contestants should be between 13 and 17 and their fee should be $20. Adults are 18 and older and their entry fee should be set to $30. The fee should be set for each class. Override the ToString() method in each class and return a string that includes all the contestant data, including the age category and the entry fee. Prompt the user for the number of contestants in this years competition, which must be between 0 and 30. The program should continue to prompt the user until a valid value is entered. The program prompts the user for the names, ages, and talent codes for the contestants entered. Along with the prompt for a talent code, display a list of valid categories. Based on the age entered for the contestant, create an object of the correct type (adult, teen, or child), and store it in an array of Contestant objects. After the data entry is complete, display the total expected revenue, which is the sum of the entry fees for the contestants. After data entry is complete, display the valid talent categories and then continuously prompt the user for talent codes, and display all the data for all the contestants in each category, this should be completed in a method. Display an appropriate message if the entered code is not a character or valid code. Create the UML diagram for the above. Write the code for the above in Visual Studio using C#. Report (Explain your development steps and test outputs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
class ContestantDemo
{
static void Main()
{
const int MIN_CONTESTANTS = 0;
const int MAX_CONTESTANTS = 30;
int num;
int revenue = 0;
const char QUIT = 'Z';
char option = ' '; ;
Contestant[] contestants = new Contestant[MAX_CONTESTANTS];
num = getContestantNumber(MIN_CONTESTANTS, MAX_CONTESTANTS);
revenue = getContestantData(num, contestants, revenue);
Console.WriteLine(" Revenue expected this year is {0}", revenue.ToString("C"));
while (option != QUIT)
option = getLists(num, contestants);
}
private static int getContestantNumber(int min, int max)
{
string entryString; int num = max + 1;
Console.Write("Enter how many contestants >> ");
entryString = Console.ReadLine();
while (num < min || num > max)
{
if (!int.TryParse(entryString, out num))
{
Console.WriteLine("Format invalid");
num = max + 1;
Console.Write("Enter how many contestants>> ");
entryString = Console.ReadLine();
}
else
{
try
{
if (num < min || num > max) throw (new ArgumentException());
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Number must be between {0} and {1}", min, max);
num = max + 1;
Console.Write("Enter how many contestants >> ");
entryString = Console.ReadLine();
}
}
}
return num;
}
private static int getContestantData(int num,
Contestant[] contestants, int revenue)
{
const int ADULTAGE = 17;
const int TEENAGE = 12;
int x = 0; string name;
char talent; int age;
int pos;
StreamWriter sw = new StreamWriter("Contestant.txt");
while (x < num)
{
Console.Write("Enter name of contestant >> ");
name = Console.ReadLine();
Console.WriteLine("Talent codes:");
for (int y = 0; y < Contestant.talentCodes.Length; ++y)
Console.WriteLine(" {0} {1}", Contestant.talentCodes[y], Contestant.talentStrings[y]);
Console.Write("Enter your talent code >> ");
char.TryParse(Console.ReadLine(),out talent);
try { validateCode(talent, out pos);
}
catch (ArgumentException e)
{
Console.WriteLine("{0} is not a valid code. Assigned as Invalid.", talent);
}
Console.Write("Enter age of contestant's >> ");
int.TryParse(Console.ReadLine(), out age);
if (age > ADULTAGE) contestants[x] = new AdultContestant();
else
if (age > TEENAGE) contestants[x] = new TeenContestant();
else
contestants[x] = new ChildContestant();
contestants[x].Name = name; contestants[x].TalentCode = talent; revenue += contestants[x].Fee; ++x; sw.WriteLine(talent + "," + age + "," + name);
sw.Flush();
sw.Close();
}
return revenue;
}
private static char getLists(int num, Contestant[] contestants)
{
int x; char QUIT = 'Z';
char option = ' ';
bool isValid;
int pos = 0;
bool found;
Console.WriteLine(" The talents and their codes are:");
for (x = 0; x < Contestant.talentStrings.Length; ++x)
Console.WriteLine("{0, -6}{1, -20}", Contestant.talentCodes[x], Contestant.talentStrings[x]);
Console.Write(" Enter your talent type or {0} to quit >> ", QUIT);
isValid = false;
while (!isValid)
{
if (!char.TryParse(Console.ReadLine(), out option))
{
isValid = false;
Console.WriteLine("Invalid format - entry must be a single character");
Console.Write(" Enter your talent type or {0} to quit >> ", QUIT); }
else
{
if (option == QUIT) isValid = true;
else
{
try
{
validateCode(option, out pos); isValid = true;
}
catch (ArgumentException e)
{
Console.WriteLine("{0} is not a valid code", option);
Console.Write(" Enter your talent type or {0} to quit >> ", QUIT);
isValid = false; }
}
if
(isValid && option != QUIT)
{
Console.WriteLine(" Contestants with talent {0} are:",
Contestant.talentStrings[pos]);
found = false;
for (x = 0; x < num; ++x)
{
if
(contestants[x].TalentCode == option)
{
Console.WriteLine(contestants[x].ToString());
found = true;
}
}
if
(!found)
{
Console.WriteLine("No contestants had talent {0}", Contestant.talentStrings[pos]);
is
Valid = false;
Console.Write(" Enter your talent type or {0} to quit >> ", QUIT);
}
}
}
}
return option;
}
public static void validateCode(char option, out int pos)
{
bool isValid = false; pos = Contestant.talentCodes.Length - 1;
for (int z = 0; z < Contestant.talentCodes.Length; ++z)
{
if
(option == Contestant.talentCodes[z])
{
is
Valid = true;
pos = z;
}
}
if
(!isValid)
throw (new ArgumentException());
}
}
class Contestant
{
public static char[] talentCodes = { 'S', 'D', 'M', 'O' };
public static string[] talentStrings = {"Singing", "Dancing", "Musical instrument", "Other"};
public string Name { get; set; }
private char talentCode;
private string talent;
private int fee;
public char TalentCode
{
get
{
return talentCode;
}
set
{
int pos = talentCodes.Length; for (int x = 0; x < talentCodes.Length; ++x)
if (value == talentCodes[x])
pos = x; if (pos == talentCodes.Length)
{
talentCode = 'I'; talent = "Invalid";
}
else
{
talentCode = value; talent = talentStrings[pos];
}
}
}
public string Talent
{
get
{
return talent;
}
}
public int Fee
{
get
{
return fee;
}
set
{
fee = value;
}
}
}
class AdultContestant : Contestant
{
public int ADULT_FEE = 30;
public AdultContestant()
{
Fee = ADULT_FEE;
}
public override string ToString()
{
return ("Adult Contestant " + Name + " " +
TalentCode + " Fee " + Fee.ToString("C"));
}
}
class TeenContestant :Contestant
{
public int TEEN_FEE = 20;
public TeenContestant()
{
Fee = TEEN_FEE;
}
public override string ToString()
{
return ("Teen Contestant " + Name + " "
+ TalentCode + " Fee " + Fee.ToString("C"));
}
}
class ChildContestant : Contestant
{ public int CHILD_FEE = 15;
public ChildContestant()
{
Fee = CHILD_FEE; }
public override string ToString()
{
return ("Child Contestant " + Name + " " +
TalentCode + " Fee " + Fee.ToString("C"));
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
