Question

In Chapter 9, you created a Contestant class for the Greenville Idol competition. The class includes...

In Chapter 9, 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 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. 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 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 each contestant, create an object of the correct type (adult, teen, or child), and store it in an array of Contestant objects. • After 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. Display an appropriate message if the entered code is not a character or a valid code. (Please use the following code)

using System.IO;
using System;

class Contestant
{
public static string[] talent_values = { "S", "D", "M", "O" };
public static string[] talent_names = { "Singing", "Dancing", "Musical instrument", "Other" };

private string name;
private string talent_codes;
private string talent_name_values;

public string getName()
{
return name;
}

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

public string getTalentCode()
{
return talent_codes;
}

public void setTalentCode(string tcode)
{
bool check = false;
int i;
for (i = 0; i < talent_values.Length; i++)
{
if (talent_values[i] == tcode)
{
check = true;
break;
}
}

if (check)
{
talent_codes = tcode;
talent_name_values = talent_names[i];
}
else
talent_codes = "I";
}

public string getTalentNames()
{
return talent_name_values;
}


}

class Program
{
static void Main(string[] args)
{

int min = 0;
int max = 30;
int entFee = 25;
int this_year;
int last_year;


Console.WriteLine("Enter the number of contestants enter in last year's competition 0-30: ");
last_year = cont_count();

Console.WriteLine("Enter the number of contestants entered in this year's competition 0-30: ");

this_year = cont_count();
array(this_year);
displayCompInfo(this_year, last_year, entFee);

}

public static int cont_count()
{
int min = 0;
int max = 30;
int entFee = 25;
int last = 0;
string b = Console.ReadLine();
int.TryParse(b, out last);
while (last < min || last > max)
{
Console.WriteLine("Your response is invalid, please enter a valid between 0-30");
b = (Console.ReadLine());
int.TryParse(b, out last);
}
return last;

}

public static void array(int this_year)
{

//string[] contestants = new String[this_year];
//string[] talent = new String[this_year];
Contestant[] contestant = new Contestant[this_year];
string name;

for (int x = 0; x < this_year; 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("\nPlease enter contestant " + (x + 1) + " 's skill, 'S' for singing 'D' for dancing 'M' for " +
"musical instrument, or 'O' for other");
string type = Console.ReadLine().ToUpper();

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

}
}
talent(contestant);
}


public static void talent(Contestant[] contestant)
{
int singing_count = 0;
int dancing_count = 0;
int musical_ins_count = 0;
int other_count = 0;
string entry;

for (int x = 0; x < contestant.Length; x++)
{
if (contestant[x].getTalentCode() == "O")
{
other_count++;
}
else if (contestant[x].getTalentCode() == "S")
{
singing_count++;
}
else if (contestant[x].getTalentCode() == "D")
{
dancing_count++;
}
else if (contestant[x].getTalentCode() == "M")
{
musical_ins_count++;
}
}

Console.Clear();
Console.WriteLine("Number of contestants singing = " + singing_count);
Console.WriteLine("Number of contestants dancing = " + dancing_count);
Console.WriteLine("Number of contestants play musical instruments = " + musical_ins_count);
Console.WriteLine("Number of contestants performing other talents = " + other_count);

Console.WriteLine("Please enter a contestant talent 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].getTalentCode())
Console.WriteLine(" Contestant " + contestant[x].getName() + " -" + contestant[x].getTalentNames());
}
Console.WriteLine("\nPlease 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();
}

}

static void displayCompInfo(int this_year, int last_year, int entFee)
{

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

Homework Answers

Answer #1

//C# Code

using System.IO;
using System;

public class Contestant
{
public static string[] talent_values = { "S", "D", "M", "O" };
public static string[] talent_names = { "Singing", "Dancing", "Musical instrument", "Other" };

protected string name;
protected string talent_codes;
protected string talent_name_values;
protected double entry_fees;

public double getEntryFees()
{
return entry_fees;
}
public void setEntryFees(double e)
{
this.entry_fees = e;
}
public string getName()
{
return name;
}

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

public string getTalentCode()
{
return talent_codes;
}

public void setTalentCode(string tcode)
{
bool check = false;
int i;
for (i = 0; i < talent_values.Length; i++)
{
if (talent_values[i] == tcode)
{
check = true;
break;
}
}

if (check)
{
talent_codes = tcode;
talent_name_values = talent_names[i];
}
else
talent_codes = "I";
}

public string getTalentNames()
{
return talent_name_values;
}

public override string ToString()
{
return "Name: " + name + "\n Talent Code: " + talent_codes + "\nTalent Name: " + talent_name_values +
"\nEntry Fees: " + entry_fees.ToString("C");
}
}

//Child classes
class ChildContestant : Contestant
{
public ChildContestant()
{
entry_fees = 15.0;
}
public override string ToString()
{
return base.ToString();
}
}

class TeenContestant :Contestant
{
public TeenContestant()
{
entry_fees = 20.0;
}
public override string ToString()
{
return base.ToString();
}
}
class AdultContestant : Contestant
{
public AdultContestant()
{
entry_fees = 30.0;
}
public override string ToString()
{
return base.ToString();
}
}

class Program
{
static void Main(string[] args)
{

int this_year;
int last_year;
//int entFee = 20;
// Console.WriteLine("Enter the number of contestants enter in last year's competition 0-30: ");
// last_year = cont_count();
/**
* 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.
*/
Console.WriteLine("Enter the number of contestants entered in this year's competition 0-30: ");

this_year = cont_count();
array(this_year);
// displayCompInfo(this_year, last_year, entFee);

}

public static int cont_count()
{
int min = 0;
int max = 30;
int entFee = 25;
int last = 0;
string b = Console.ReadLine();
int.TryParse(b, out last);
while (last < min || last > max)
{
Console.WriteLine("Your response is invalid, please enter a valid between 0-30");
b = (Console.ReadLine());
int.TryParse(b, out last);
}
return last;

}

public static void array(int this_year)
{
/**
* The program prompts the user for 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 each contestant, create an object of
* the correct type (adult, teen, or child),
* and store it in an array of Contestant objects.
*/
Contestant[] contestant = new Contestant[this_year];
string name;
int age = 0;
for (int x = 0; x < this_year; x++)
{
Console.WriteLine("Please enter contestant " + (x + 1) + "'s name");
name = Console.ReadLine();
Console.WriteLine("Please enter contestant " + (x + 1) + "'s age");
age = int.Parse(Console.ReadLine());
if (age < 12)
contestant[x] = new ChildContestant();
else if (age > 12 && age <= 17)
contestant[x] = new TeenContestant();
else
contestant[x] = new AdultContestant();
contestant[x].setName(name);

bool correct = false;
while (!correct)
{
Console.WriteLine("\nPlease enter contestant " + (x + 1) + " 's skill, 'S' for singing 'D' for dancing 'M' for " +
"musical instrument, or 'O' for other");
string type = Console.ReadLine().ToUpper();

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

}
}
  
talent(contestant);
displayContestantInfo(contestant);
displayRevenueInfo(contestant);
Console.ReadLine();
}


public static void talent(Contestant[] contestant)
{
int singing_count = 0;
int dancing_count = 0;
int musical_ins_count = 0;
int other_count = 0;
string entry;

for (int x = 0; x < contestant.Length; x++)
{
if (contestant[x].getTalentCode() == "O")
{
other_count++;
}
else if (contestant[x].getTalentCode() == "S")
{
singing_count++;
}
else if (contestant[x].getTalentCode() == "D")
{
dancing_count++;
}
else if (contestant[x].getTalentCode() == "M")
{
musical_ins_count++;
}
}

Console.Clear();
Console.WriteLine("Number of contestants singing = " + singing_count);
Console.WriteLine("Number of contestants dancing = " + dancing_count);
Console.WriteLine("Number of contestants play musical instruments = " + musical_ins_count);
Console.WriteLine("Number of contestants performing other talents = " + other_count);

Console.WriteLine("Please enter a contestant talent 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].getTalentCode())
Console.WriteLine(" Contestant " + contestant[x].getName() + " -" + contestant[x].getTalentNames());
}
Console.WriteLine("\nPlease 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();
}

}
/**
* display Contestant Info
*/
static void displayContestantInfo(Contestant[] contestants)
{
Console.WriteLine("Contestants's Info: ");
foreach(Contestant c in contestants)
{
Console.WriteLine(c);
}
}
/**
* display the total expected revenue, which is the sum of the entry fees for the contestants.
*/
static void displayRevenueInfo(Contestant[] contestants)
{
double sum = 0.0;
foreach(Contestant c in contestants)
{
sum += c.getEntryFees();
}
Console.WriteLine("Expected Revenue: " + sum.ToString("C"));
}
static void displayCompInfo(int this_year, int last_year, int entFee)
{

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

//output

//If you need any help regarding this solution ........... please leave a comment ......... thanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
using System; public static class Lab5 { public static void Main() { // declare variables int...
using System; public static class Lab5 { public static void Main() { // declare variables int inpMark; string lastName; char grade = ' '; // enter the student's last name Console.Write("Enter the last name of the student => "); lastName = Console.ReadLine(); // enter (and validate) the mark do { Console.Write("Enter a mark between 0 and 100 => "); inpMark = Convert.ToInt32(Console.ReadLine()); } while (inpMark < 0 || inpMark > 100); // Use the method to convert the mark into...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by...
1.If you have defined a class,  SavingsAccount, with a public  static method,  getNumberOfAccounts, and created a  SavingsAccount object referenced by the variable  account20, which of the following will call the  getNumberOfAccounts method? a. account20.getNumberOfAccounts(); b. SavingsAccount.account20.getNumberOfAccounts(); c. SavingsAccount.getNumberOfAccounts(); d. getNumberOfAccounts(); e. a & c f. a & b 2.In the following class, which variables can the method printStats use? (Mark all that apply.) public class Item { public static int amount = 0; private int quantity; private String name; public Item(String inName, int inQty) { name...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String...
please fix code to delete by studentname import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String[] students = new String[1];     private int numberOfStudents;     public COurseCom666(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public void addStudent(String student) {         if (numberOfStudents == students.length) {             String[] a = new String[students.length + 1];            ...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
Design a program that calculates the amount of money a person would earn over a period...
Design a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT