Question

Case Program 10 – 1: Part 1: Previously, you created a Contestant class for the Greenville Idol c...

Case Program 10 – 1:

Part 1:

Previously, you created a Contestant class for the Greenville Idol competition. The class includes a contestant’s name, talent code, and talent description. The competition has become so popular that separate contests with differing entry fees have been established for children, teenagers, and adults.

Modify the Contestant class to contain a field Fee that holds the entry fee for each category, and add get and set accessors. Extend the Contestant class to create three subclasses: ChildContestant, TeenContestant, and AdultContestant.

Child contestants are 12 years old and younger, and their entry fee is $15. Teen contestants are between 13 and 17 years old, inclusive, and their entry fee is $20. Adult contestants are 18 years old and older, and their entry fee is $30. In each subclass, set the entry fee field to the correct value, and override the ToString() method to return a string that includes all the contestant data, including the age category and the entry fee.

For example, the output from ToString() should be displayed in the following format: Child Contestant Joeph S Fee $15.00 Teen Contestant Sara M Fee $20.00 Adult Contestant Joy D Fee $30.00

Part 2:

Modify the GreenvilleRevenue program so that it performs the following tasks:

The program prompts the user for the number of contestants in this year’s competition, which must be between 0 and 30. The program continues to prompt the user until a valid value is entered. The program prompts the user for the name, talent code, and age for each contestant. Along with the prompt for a talent code, display a list of valid categories. Based on the age entered for each contestant, create an object of the correct type (adult, teen, or child), and store it in an array of Contestant objects. Talent code categories should be displayed in the following format: Talent codes are: S Singing D Dancing M Musical instrument O Other After data entry is complete, display the total expected revenue, which is the sum of the entry fees for the contestants.

The total expected revenue should be displayed in the following format: Revenue expected this year is $65.00.

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 (using the ToString method for each contestant). Display an appropriate message if the entered code is not a character or a valid code.

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

using System;

namespace Wk4Chapter9
{
class Chapter9
{
static void Main()
{
int thisYearContestants;
int lastYearContestants;

Console.WriteLine("Please enter the number of contestants entered in last year's competition: ");
lastYearContestants = GetContestants();

Console.WriteLine("Please enter the number of contestants entered in this year's competition: ");
thisYearContestants = GetContestants();

DisplayContestantMessage(thisYearContestants, lastYearContestants); //revenue + contestant message

Contestant[] contestants = new Contestant[thisYearContestants];

FillArrays(thisYearContestants, contestants);
// PromptTalentCodes(thisYearContestants, contestants);
double totalrevenue = 0;
foreach (Contestant c in contestants)
{
totalrevenue += c.EntryFee;
//Display contestants
Console.WriteLine(c);
}
Console.WriteLine("Total Revenue: $" + totalrevenue);
}


static int GetContestants()
{
int contestants;
string input = Console.ReadLine();

while (!Int32.TryParse(input, out contestants) || (contestants < 0 || contestants > 30))
{

Console.WriteLine("Error. Please enter a value between 0 and 30.");
input = Console.ReadLine();
}
return contestants;
} //end GetContestants method


static void DisplayContestantMessage(int thisYearContestants, int lastYearContestants)
{
if ((lastYearContestants >= 0) && (lastYearContestants <= 30) && (thisYearContestants >= 0) && (thisYearContestants <= 30))
Console.WriteLine("The revenue expected for this year's competition : $" + thisYearContestants * 25 + '\n');
if (thisYearContestants > lastYearContestants * 2)
Console.WriteLine("The competition is more than twice as big this year!\n");
else
if (thisYearContestants > lastYearContestants && thisYearContestants <= (lastYearContestants * 2))
Console.WriteLine("The competition is bigger than ever!\n");
else
if (thisYearContestants < lastYearContestants)
Console.WriteLine("A tighter race this year! Come out and cast your vote!\n");
} // end DisplayContestantMessage

static void FillArrays(int thisYearContestants, Contestant[] contestants)
{
int x = 0;
string name;
int age;
char talent;
while (x < thisYearContestants)
{
Console.WriteLine("Enter Contestant Name: ");
name = Console.ReadLine();
Console.WriteLine("Enter Contestant age: ");
int.TryParse( Console.ReadLine(),out age);
Console.WriteLine("Talent codes are:");
for (int k = 0; k < Contestant.talentCodes.Length; ++k)
Console.WriteLine(" {0} {1}", Contestant.talentCodes[k], Contestant.talentStrings[k]);
Console.WriteLine("Please enter contestant " + (x + 1) + "'s talent code: ");

char.TryParse(Console.ReadLine(), out talent);
if (age <= 12)
{
contestants[x] = new ChildContestant();
contestants[x].Name = name;
contestants[x].TalentCode = talent;
++x;
}
else if (age >12 && age <=17)
{
contestants[x] = new TeenContestant();
contestants[x].Name = name;
contestants[x].TalentCode = talent;
++x;
}
else
{
contestants[x] = new AdultContestant();
contestants[x].Name = name;
contestants[x].TalentCode = talent;
++x;
}
}
}// end FillArrays method


static void PromptTalentCodes(int thisYearContestants, Contestant[] contestants)
{
int x;
char QUIT = 'Q';
char input;
bool isValid;
int pos = 0;
bool correct;

Console.WriteLine("\n ********************************************************** \n");

Console.WriteLine("To see the contestants by talent, please search a valid talent code or " + QUIT + " to quit: ");
Console.WriteLine("\nThe types of talent are:");
for (x = 0; x < Contestant.talentStrings.Length; ++x)
Console.WriteLine("{0, -6}{1, -20}", Contestant.talentCodes[x], Contestant.talentStrings[x]); //taken from ch9 sample problem

isValid = false;
while (!isValid)
{
if (!char.TryParse(Console.ReadLine(), out input)) // if user enters an invalid code
{
isValid = false;
Console.WriteLine("\nInvalid talent code. Please enter a valid talent code or " + QUIT + " to quit: ");
}
else
{
if (input == QUIT) // if user enters the Q to quit
isValid = true;
else
{
for (int k = 0; k < Contestant.talentCodes.Length; ++k)
{
if (input == Contestant.talentCodes[k]) // if user enters a valid talent code
{
isValid = true;
}
}
if (!isValid) //if user enters invalid talent code
{
Console.WriteLine(input + " is not a valid code.\n Please enter a talent code or " + QUIT + " to quit: ");
}
else
{
Console.WriteLine("\nContestants with talent " + input + "are: ");
correct = false;
for (x = 0; x < thisYearContestants; ++x)
{
if (contestants[x].TalentCode == input)
{
Console.WriteLine(contestants[x].Name);
correct = true;
}
}
if (!correct)
Console.WriteLine("No contestants entered with talent " + input + ".");
isValid = false;
Console.Write("\nEnter another talent code or " + QUIT + " to quit: ");
}
}
}
}
} // end PromptTalentCodes method

} //end first class


public 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 double entryFee;
public double EntryFee
{
get
{
return entryFee;
}
set
{
entryFee = value;
}
}
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 class ChildContestant : Contestant
{
public ChildContestant()
{
EntryFee = 15;
}
public override string ToString()
{
return "Name: " + Name + "\n Talent Code: " + TalentCode +
"\n Talent Description: " + Talent + "\nEntry Fee: " + EntryFee +
"\nAge Category: Child";
}
}
public class TeenContestant:Contestant
{
public TeenContestant()
{
EntryFee = 20;
}
public override string ToString()
{
return "Name: " + Name + "\n Talent Code: " + TalentCode +
"\n Talent Description: " + Talent + "\nEntry Fee: " + EntryFee +
"\nAge Category: Teen";
}
}
public class AdultContestant:Contestant
{
public AdultContestant()
{
EntryFee = 30;
}
public override string ToString()
{
return "Name: " + Name + "\n Talent Code: " + TalentCode +
"\n Talent Description: " + Talent + "\nEntry Fee: " + EntryFee +
"\nAge Category: Adult";
}
}
  


} // end namespace

//output

S Singing D Dancing M Musical instrument o Other Please enter contestant 2s talent code: Enter Contestant Name Britney Enter

Add a comment
Know the answer?
Add Answer to:
Case Program 10 – 1: Part 1: Previously, you created a Contestant class for the Greenville Idol c...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now...

    Use a C# In previous chapters, you have created programs for the Greenville Idol competition. Now create a Contestant class with the following characteristics: The Contestant class contains public static arrays that hold talent codes and descriptions. Recall that the talent categories are Singing, Dancing, Musical instrument, and Other. Name these fields talentCodes and talentStrings respectively. The class contains an auto-implemented property Name that holds a contestant’s name. The class contains fields for a talent code (talentCode) and description (talent)....

  • In Chapter 1, you created two programs to display the motto for the Greenville Idol competition...

    In Chapter 1, you created two programs to display the motto for the Greenville Idol competition that is held each summer during the Greenville County Fair. Now 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...

  • Case Problem 11 - 1: Modify the GreenvilleRevenue program created in the previous chapter so that...

    Case Problem 11 - 1: 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 year’s competition; the number must be between 0 and 30. Use exception-handling techniques to ensure a valid value and display the error message: Number must be between 0 and 30 The program prompts the user for talent codes. Use exception-handling techniques to ensure a valid code and...

  • In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the...

    In Chapter 11, you created the most recent version of the GreenvilleRevenue program, which prompts the user for contestant data for this year’s Greenville Idol competition. Now, save all the entered data to a Greenville.ser file that is closed when data entry is complete and then reopened and read in, allowing the user to view lists of contestants with requested talent types. The program should output the name of the contestant, the talent, and the fee. using System; using static...

  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program...

    Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone...

    For Python 3.8! Copy and paste the following bolded code into IDLE: movies = [[1939, 'Gone with the Wind', 'drama'],           [1943, 'Casablanca', 'drama'],           [1965, 'The Sound of Music', 'musical'],           [1969, 'Midnight Cowboy', 'drama'],           [1972, 'The Godfather', 'drama'],           [1973, 'The Sting', 'comedy'],           [1977, 'Annie Hall', 'comedy'],           [1982, 'Ghandi', 'historical'],           [1986, 'Platoon', 'action'],           [1990, 'Dances with Wolves', 'western'],           [1992, 'Unforgiven', 'western'],           [1994, 'Forrest Gump', 'comedy'],           [1995, 'Braveheart', 'historical'],           [1997,...

  • PLEASE ANSWER IN C# 5. a. Create a Patient class for the Wrightstown Hospital Billing Department....

    PLEASE ANSWER IN C# 5. a. Create a Patient class for the Wrightstown Hospital Billing Department. Include auto-implemented prop- erties for a patient ID number, name, age, and amount due to the hospital, and include any other methods you need. Override the ToString method to return all the details for a patient. Write an application that prompts the user for data for five Patients. Sort them in patient ID number order and display them all, including a total amount owed....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT