How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Raj Your Own Question

Raj
Raj, Engineer
Category: Homework
Satisfied Customers: 1259
Experience:  4 + Experiance in IT Industry
16752232
Type Your Homework Question Here...
Raj is online now
A new question is answered every 9 seconds

You are going to code a program for a new golf league. The

Resolved Question:

You are going to code a program for a new golf league.

The program will need to have the following:

1. An array of a variable number of golf teams (max 10).
2. Classes for the following:
a. A Team class containing team name, an array of 4 Player objects, and scoring rank of team.
b. A Player class containing first name, last name, handicap, score for last game and rank on team.
3. The program should offer the user the option of entering teams, player data and scores, and should calculate the scores and rankings for the teams and the league.
4. A sorted list of team information should be written to a file.
5. The user should be able to display all information


Your application must include the following:

Constructors
Delegate
Arrays
Abstract Class or Interface
Exception Handling
Static Data Members
Overloaded Operator or overridden method
MessageBox
Inheritance
Data Validation
File Input/Output
Value Added - something not listed above
Submitted: 1 year ago.
Category: Homework
Expert:  Angela--Mod replied 1 year ago.
Thank you for your patience, your business is very important to us, we are waiting on the professional with the right expertise to come online. Please let us know if you would like us to continue searching for a professional or if you would like us to close your question. Thank you for your understanding!
Customer: replied 1 year ago.
Continue searching.
Expert:  Angela--Mod replied 1 year ago.
Thank you for your continued patience. I have marked your question high priority. You'll receive an email notification as soon as a professional replies. Best,

Angela
Expert:  Raj replied 1 year ago.
Hi there,

I can help you with the requirement.
By when do you need the solution?

Thank you
Customer: replied 1 year ago.
If you can, i need it by 22 may. Thank You.
Expert:  Raj replied 1 year ago.
I will try my beat to finish this by then


Have a good day.
Customer: replied 1 year ago.
Here is sample:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace ABCGolf
{
public partial class Form1 : Form, ITeam
{
// Global Variables for all of Form1 to access
string playeraddTeam = "";
List myTeams = new List(10);
string TeamText = "";
Team myteam = new Team();
private const int NOTFOUND = 99999;

public Form1()
{
InitializeComponent();
} // End Form1 constructor

private void btnClearTeam_Click(object sender, EventArgs e)
{
txtTeamName.Clear();
txtTeamRank.Clear();
} // End btnClearTeam_Click method

private void btnAddUpdateTeam_Click(object sender, EventArgs e)
{
try
{
if (txtTeamRank.Text != "" && txtTeamName.Text != "")
{
int teamrnk = Convert.ToInt16(txtTeamRank.Text);
Team myteam = new Team(txtTeamName.Text, teamrnk);
TeamText = txtTeamName.Text;
int theTruth = GetTheTruth(myTeams, myteam.TeamName);

if (theTruth == 1)
{
int Location = TeamGetIndex(myTeams, txtTeamName.Text);
myTeams.RemoveAt(Location);
cbUpdateTeam.Items.Remove(txtTeamName.Text);
}
if (myTeams.Count < 10)
{
myTeams.Add(myteam);
cbUpdateTeam.Items.Add(txtTeamName.Text);
cbViewTeam.Items.Add(txtTeamName.Text);
cbPlayerTeams.Items.Add(txtTeamName.Text);
}
else
{
MessageBox.Show("You must remove a team before entering a another team.");
}
txtTeamName.Clear();
txtTeamRank.Clear();
}
else
{
MessageBox.Show("You must enter a Value for both fields");
}
}
catch (Exception v)
{
MessageBox.Show(v.Message);
}
} // End btnAddUpdateTeam_Click method

public int TeamGetIndex(List myTeams, string p)
{
// Local Method Variables
int Index = 0;

foreach (Team I in myTeams)
{
if (I.TeamName == p)
{
return Index;
}
Index++;
}
// Team not found
Index = NOTFOUND;
return Index;
} // End TeamGetIndex method

public int PlayerGetIndex(List myPlayers, string p)
{
int Index = 0;
foreach (Golfer I in myPlayers)
{
if (I.LastName == p)
{
return Index;
}
Index++;
}
Index = NOTFOUND;
return Index;
} // End PlayerGetIndex method

private int GetTheTruth(List myTeams, string p)
{
foreach (Team I in myTeams)
{
if (I.TeamName == p)
{
return 1;
}
}
return 0;
} // End GetTheTruth method

private void cbUpdateTeam_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string name = cbUpdateTeam.SelectedItem.ToString();
Team theTeam = (from x in myTeams where x.TeamName == name select x).FirstOrDefault();

txtTeamName.Text = theTeam.TeamName;
TeamText = txtTeamName.Text;
txtTeamRank.Text = theTeam.TeamRank.ToString();
}
catch (Exception a)
{
MessageBox.Show(a.Message);
}
} // End cbUpdateTeam_SelectedIndexChanged method

private void btnDeleteTeam_Click(object sender, EventArgs e)
{
try
{
int Location2 = TeamGetIndex(myTeams, TeamText);
myTeams.RemoveAt(Location2);
cbUpdateTeam.Items.Remove(TeamText);
cbViewTeam.Items.Remove(TeamText);
cbPlayerTeams.Items.Remove(TeamText);
txtTeamName.Clear();
txtTeamRank.Clear();
cbUpdateTeam.Text = "";
}
catch (Exception m)
{
MessageBox.Show(m.Message);
}
} // End btnDeleteTeam_Click_1 method

private void cbViewTeam_SelectedIndexChanged(object sender, EventArgs e)
{
// Local Method Variables
Team gridteam = new Team();
try
{
gridteam = (from x in myTeams where x.TeamName == cbViewTeam.Text select x).FirstOrDefault();
if (gridteam.Players.Count != 0)
{
int counter = 0;
if (dataGridView1.Rows.Count > 1)
{
// Remove in decending order as rows are reindexed with each remove
dataGridView1.Rows.RemoveAt(3);
dataGridView1.Rows.RemoveAt(2);
dataGridView1.Rows.RemoveAt(1);
dataGridView1.Rows.RemoveAt(0);
}
foreach (Golfer i in gridteam.Players)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[counter].Cells[0].Value = i.FirstName;
dataGridView1.Rows[counter].Cells[1].Value = i.LastName;
dataGridView1.Rows[counter].Cells[2].Value = i.Handicap;
dataGridView1.Rows[counter].Cells[3].Value = i.RankOnTeam;
counter++;
}
}
else
{
MessageBox.Show("There are no Players entered on the Team you selected");
}
}
catch (Exception o)
{
MessageBox.Show(o.Message);
}
} // End cbViewTeam_SelectedIndexChanged method

private void cbTeams_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
lbMembers.Items.Clear();
playeraddTeam = cbPlayerTeams.Text;
Team LTeam = (from x in myTeams where x.TeamName == playeraddTeam select x).FirstOrDefault();
if (myTeams.Count != 0)
{
if (LTeam.Players != null)
{
foreach (Golfer i in LTeam.Players)
{
lbMembers.Items.Add(i.FirstName + " " + i.LastName);
}
}
}
else
{
MessageBox.Show("You have to Add a Team before you can add an Golfer");
}
}
catch (Exception l)
{
MessageBox.Show(l.Message);
}
} // End cbTeams_SelectedIndexChanged method

private void btnAddUpdate_Click(object sender, EventArgs e)
{
// Local Method Variables
Team myteam = new Team();
Golfer i = new Golfer();
try
{
if (cbPlayerTeams.Text != "")
{
i.FirstName = txtFName.Text;
i.LastName = txtLName.Text;
i.RankOnTeam = Convert.ToInt32(txtRank.Text);
i.LastGame = Convert.ToInt32(txtLastScore.Text);
i.Handicap = Convert.ToInt32(txtHandiCap.Text);
// GetTeam is an existing team in the list. At this point we don't need the myteam
Team GetTeam = (from t in myTeams where t.TeamName == cbPlayerTeams.Text select t).FirstOrDefault();
if (GetTeam.Players.Count < 4)
{
GetTeam.Players.Add(i);
lbMembers.Items.Add(i.FirstName + " " + i.LastName);
}
else
{
MessageBox.Show("You must remove a team member before entering a another player.");
}
/*************************************************************************/
txtFName.Clear();
txtLName.Clear();
txtRank.Clear();
txtLastScore.Clear();
txtHandiCap.Clear();
}
else
{
MessageBox.Show("You must Select a Team before entering a player");
}
}
catch (Exception u)
{
MessageBox.Show(u.Message);
}
} // End btnAddUpdate_Click method

private void LoadData_Click(object sender, EventArgs e)
{
myTeams = ReadXML();
PopulateComboboxes();
} // End LoadTeams_Click method

private void SaveData_Click(object sender, EventArgs e)
{
WriteXML(myTeams);
} // End SaveTeams_Click method

private void Exit_Click(object sender, EventArgs e)
{
this.Dispose();
} // End Exit_Click method

private void About_Click(object sender, EventArgs e)
{
AboutBox About = new AboutBox();
About.Show();
} // End LoadTeams_Click method

private void lbMembers_SelectedIndexChanged(object sender, EventArgs e)
{
// Local Method Variables
Golfer lbGolfer = new Golfer();
Team lbTeam = new Team();
try
{
lbTeam = (from x in myTeams where x.TeamName == cbPlayerTeams.Text select x).FirstOrDefault();
lbGolfer = (from i in lbTeam.Players where i.FirstName + " " + i.LastName == lbMembers.SelectedItem.ToString() select i).FirstOrDefault();//.Contains(lbMembers.SelectedItem.ToString()) select i).FirstOrDefault();
if (lbGolfer != null)
{
txtFName.Text = lbGolfer.FirstName;
txtLName.Text = lbGolfer.LastName;
txtHandiCap.Text = lbGolfer.Handicap.ToString();
txtLastScore.Text = lbGolfer.LastGame.ToString();
txtRank.Text = lbGolfer.RankOnTeam.ToString();
}
}
catch (Exception z)
{
MessageBox.Show(z.Message);
}
} // End lbMembers_SelectedIndexChanged method

private void btnDeleteplayer_Click(object sender, EventArgs e)
{
// Local Method Variables
Golfer lbGolfer = new Golfer();
Team lbTeam = new Team();
try
{
lbTeam = (from x in myTeams where x.TeamName == cbPlayerTeams.Text select x).FirstOrDefault();
myTeams.Remove(lbTeam);
lbGolfer = (from i in lbTeam.Players where i.FirstName + " " + i.LastName == lbMembers.SelectedItem.ToString() select i).FirstOrDefault();
lbTeam.Players.Remove(lbGolfer);
myTeams.Add(lbTeam);
lbMembers.Items.Remove(lbMembers.SelectedItem); //lbMembers.Text.StartsWith(lbGolfer.FirstName);// Remove(lbGolfer.FirstName + " " + lbGolfer.LastName);
txtFName.Clear();
txtLName.Clear();
txtRank.Clear();
txtLastScore.Clear();
txtHandiCap.Clear();
}
catch (Exception n)
{
MessageBox.Show(n.Message);
}
} // End btnDeleteplayer_Click method

private void btnThisTeam_Click(object sender, EventArgs e)
{
// Local Method Variables
Team singleteamreport = new Team();

singleteamreport = (from x in myTeams where x.TeamName == cbViewTeam.Text select x).FirstOrDefault();
int length = singleteamreport.Players.Count();
int counter = 1;
String[] ReportOut = new String[length + 1];

ReportOut[0] = "***********TEAM " + singleteamreport.TeamName + " Ranked #" + singleteamreport.TeamRank.ToString() + "****************";
foreach (Golfer i in singleteamreport.Players)
{
string rep = "Golfer: " + i.FirstName + " " + i.LastName + " Handicap: " + i.Handicap.ToString() + " Last Score: " + i.LastGame.ToString() + " Rank: " + i.RankOnTeam.ToString();
ReportOut[counter] = rep;
counter++;
}
File.WriteAllLines(tbFilePath.Text, ReportOut);
} // End btnThisTeam_Click method

private void btnAllTeams_Click(object sender, EventArgs e)
{
foreach (Team Allteamreport in myTeams)
{
int length = Allteamreport.Players.Count();
int counter = 1;
String[] ReportOut = new String[length + 1];

ReportOut[0] = "***********TEAM " + Allteamreport.TeamName + " Ranked #" + Allteamreport.TeamRank.ToString() + "****************";
foreach (Golfer i in Allteamreport.Players)
{
string rep = "Golfer: " + i.FirstName + " " + i.LastName + " Handicap: " + i.Handicap.ToString() + " Last Score: " + i.LastGame.ToString() + " Rank: " + i.RankOnTeam.ToString();
ReportOut[counter] = rep;
counter++;
}
File.WriteAllLines(tbFilePath.Text, ReportOut);
} // End foreach
} // End btnAllTeams_Click method

private void btnbtnCalucateTeamRanks_Click(object sender, EventArgs e)
{
// Calculate the players rankings then use the best players score to rank the teams
try
{
CalculateTeamMemberRankings();
CalculateTeamScore();
MessageBox.Show("Calculation is complete");
}
catch (Exception n)
{
MessageBox.Show(n.Message);
}
} // End btnbtnCalucateTeamRanks_Click method

private void CalculateTeamMemberRankings()
{
// Local Method Variables
Golfer teamMember = new Golfer();
int counter = 1;

foreach (Team team in myTeams)
{
// Sort Team members on best score
team.Players.Sort(delegate(Golfer p1, Golfer p2)
{
return p1.Score().CompareTo(p2.Score());
});

// Set rank on team based on position in list
foreach (Golfer golfer in team.Players)
{
golfer.RankOnTeam = counter;
counter++;
}
// Reset counter for next teams ranking
counter = 1;
}
} // End CalculateTeamMemberRankings method

private void CalculateTeamScore()
{
// Local Method Variables
Golfer teamMember = new Golfer();
int counter = 1;

// Sort Teams on #1 players score
myTeams.Sort(delegate(Team t1, Team t2)
{
return t1.Score().CompareTo(t2.Score());
});

foreach (Team team in myTeams)
{
team.TeamRank = counter;
counter++;
}
} // End CalculateTeamScore method

private void PopulateComboboxes()
{
// This method is required because the comboboxes do not have the Team list as their data source
foreach (Team team in myTeams)
{
cbUpdateTeam.Items.Add(team.TeamName);
cbViewTeam.Items.Add(team.TeamName);
cbPlayerTeams.Items.Add(team.TeamName);
}
} // End PopulateComboboxes method

static List ReadXML()
{
XmlSerializer reader = new XmlSerializer(typeof(List));
StreamReader file = new StreamReader(@"GolfTeams.xml");
List teams;
teams = (List)reader.Deserialize(file);
file.Close();

return teams;
} // End ReadXML(List) method

static public void WriteXML(List teams)
{
XmlSerializer writer = new XmlSerializer(typeof(List));

StreamWriter file = new StreamWriter(@"GolfTeams.xml");
teams.Sort(delegate(Team t1, Team t2)
{
return t1.TeamRank.CompareTo(t2.TeamRank);
});
writer.Serialize(file, teams);
file.Close();
}

private void Form1_Load(object sender, EventArgs e)
{

} // End WriteXML(List) method
} // End Form1 cLass
} // End Namespace
Customer: replied 1 year ago.
Can you finish it now?
Expert:  Raj replied 1 year ago.
I am at office so cant work on it now...
Will 12 hrs be fine with you?
Customer: replied 1 year ago.
Ok.12 hours will be fine
Expert:  Raj replied 1 year ago.
Ok than see you after 12 hrs.
Customer: replied 1 year ago.
Ok
Expert:  Raj replied 1 year ago.
Ok
Customer: replied 1 year ago.
So, I will get it ready within time frame . Thanks.
Expert:  Raj replied 1 year ago.
Yea definately.
Customer: replied 1 year ago.
How long does it take now?
Expert:  Raj replied 1 year ago.
Give me 2-3 more hrs.

Also What you provided me is GUI based code and what I am doing is console based code like the last one i did and for writing in the file I am using TXT file not XML File.

Is it fine with you?
Customer: replied 1 year ago.
Ok
Customer: replied 1 year ago.
Can you make it work it on form too ?
Customer: replied 1 year ago.
If you add references and make console app work as form. That will be great.
Customer: replied 1 year ago.
So, it will be ready in hour or two now.
Expert:  Raj replied 1 year ago.
Yes but form conversion will take lot of time which is not possible now in short time.
Customer: replied 1 year ago.
Ok.It will be more better with form conversion.
Expert:  Raj replied 1 year ago.
Than I will have to change the major part of codes which will again be needing approx 24 hrs because I am busy with my work for 12 hrs so i get only 6 hrs to work on your project and 6 hrs. to sleep.
So will 24 hrs. work If you need in form or you need in console based?
Customer: replied 1 year ago.
Ok. By tomorrow this time will be fine
Customer: replied 1 year ago.
you can give me both version console and form by tomorrow this time. OR you can give me console now and form version tomorrow.Thanks.
Expert:  Raj replied 1 year ago.
Ok I will try to post both otherwise Form code for sure because I already started changing on the orignal project.
Customer: replied 1 year ago.
That will be great.Both will be awesome.
Expert:  Raj replied 1 year ago.
Ok I will provide both.
Customer: replied 1 year ago.
Hi, you said you gonna finish by tonight right.
Customer: replied 1 year ago.
How long does it take now?
Customer: replied 1 year ago.
Hi, Are you going to finish by tonight right?
Expert:  Raj replied 1 year ago.
Yes how many hrs. Are left?
Customer: replied 1 year ago.
How many more hours you need?
Expert:  Raj replied 1 year ago.
Some where around 3 hrs.
Customer: replied 1 year ago.
Ok. 3-4 hrs will be perfectly fine.
Expert:  Raj replied 1 year ago.
Ok than will leave you a message when done.
Customer: replied 1 year ago.
Ok.I will check back after3-4 hrs.
Customer: replied 1 year ago.
Is it done now?
Customer: replied 1 year ago.
How long does it take from here?
Customer: replied 1 year ago.
I am waiting for your reply.
Customer: replied 1 year ago.
Hello, you said 3-4 hrs. But. It is more than that. Can you please tell me how long do you gonna take more? Are you able to give me today?
Customer: replied 1 year ago.
You are still working with question.Thanks.
Customer: replied 1 year ago.
I did not see any solution here. If you need little bit more time, let me know.
Customer: replied 1 year ago.
Hi, I did not hear from you.Are you able to give me by tonight or not?Thanks.
Customer: replied 1 year ago.
Relist: No answer yet.
Customer: replied 1 year ago.
I don't know why I relisted again.Are you still working on this right.
Customer: replied 1 year ago.
Hi, Are you still working on it?
Customer: replied 1 year ago.
Hi, you must be busy with something. But, if you get time, please reply me.
Customer: replied 1 year ago.
Hello
Customer: replied 1 year ago.

Hi,


I would like to know when you gonna finish this?

Customer: replied 1 year ago.
Can I still depend on you or I have to find other ways?
Customer: replied 1 year ago.
Relist: No answer yet.
Expert:  Josie-Mod replied 1 year ago.
Hi, I'm a Moderator for this topic. I've been working hard to find a professional to assist you right away, but sometimes finding the right professional can take a little longer than expected.

I wonder whether you're ok with continuing to wait for an answer. If you are, please let me know and I will continue my search. If not, feel free to let me know and I will cancel this question for you. Thank you!
Customer: replied 1 year ago.
Yep
Expert:  Josie-Mod replied 1 year ago.
Thank you for your continued patience. We will continue the search for a professional for you.
Customer: replied 1 year ago.

Console application will be good.

Customer: replied 1 year ago.

May be Raj can give me console app.

Expert:  Raj replied 1 year ago.
I am really sorry for not replying here.
Was out of city with no inter net connection there.
Was sent there by my company for project.
Just came back home.

Do you still need the solution files?
Customer: replied 1 year ago.
Can you give me by tonight?
Customer: replied 1 year ago.
Console or form based whatever would be easy is fine.
Customer: replied 1 year ago.
Yep.
Expert:  Raj replied 1 year ago.
OK I will definitely reply with an solution before midnight
Customer: replied 1 year ago.
Thanks.That will work.
Expert:  Raj replied 1 year ago.
You are welcome.
Customer: replied 1 year ago.
So, u have all the requirements right.
Customer: replied 1 year ago.
Hi, console or windows form any will be fine.
Customer: replied 1 year ago.
Hi, you will be able to give me solution tonight. Let me know if you need more hours. Thanks.
Customer: replied 1 year ago.
Raj, Are you going to give me solution on this or not? Please let me know.Thanks.
Customer: replied 1 year ago.
I believe you will reply with solution. Thanks.
Expert:  Raj replied 1 year ago.
Almost done. Give me 30 min max.
Customer: replied 1 year ago.
Ok. Take your time. No rush. If I get it by tonight . It will be perfectly fine.
Expert:  Raj replied 1 year ago.
I have compressed the whole project together.
The Output file is generated after you exit using the Menu Option 4 and is Generated with name Golf_Team.txt at the below path of the project folder.

Golf_league\Golf_league\bin\Debug

Please download the Compressed solution file(Golf_league.zip) freom the link below:
http://www.mediafire.com/?v4xvxv5yw5eyjpu

If you face any difficulty than feel free to ask for help.

If the solution file is satisfactory than Please don't forget to RATE the Answer.
It will hardly take few seconds to RATE my Answer

Thank You and Have a Good Day.


Customer: replied 1 year ago.

i did not see any output.

Customer: replied 1 year ago.

here is code :


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace ConsoleApplication1
{
/*----------------------START OF PLAYER CLASS------------------------------------*/
//PLAYER CLASS
//Player Class consists of the main variables for a player
// and their respective GET/SETs
public class Player
{
//Variable Declarations
string firstName, lastName, msg;
double handicap;
int lastGameScore;


//Read-Write Property
public string FirstName
{
get
{
return firstName;
}
set
{
msg = "\nYou did not enter a valid First name...Please try again.\n";
if (value.Length == 0)
throw (new Exception(msg));
for (int j = 0; j < value.Length; j++)
{
if (!char.IsLetter(value, j))
throw (new Exception(msg));
}
firstName = value;
}
}


//GET/SET For lastName variable
public string LastName
{
get
{
return lastName;
}
set
{
msg = "\nYou did not enter a valid Last name...Please try again.\n";
if (value.Length == 0)
throw (new Exception(msg));
for (int j = 0; j < value.Length; j++)
{
if (!char.IsLetter(value, j))
throw (new Exception(msg));
}
lastName = value;
}
}


//GET/SET For handicap variable
public double Handicap
{
get
{
return handicap;
}
set
{
msg = "\nYou did not enter a valid handicap...Please try again.\n";
if (value < 0)
throw (new Exception(msg));
handicap = value;
}
}


//GET/SET For lastGameScore variable
public int LastGameScore
{
get
{
return lastGameScore;
}
set
{
msg = "\nYou did not enter a valid score...Please try again.\n";
if (value < 9)
throw (new Exception(msg));
lastGameScore = value;
}
}


//GET/SET For playerTeamRank variable
public int PlayerTeamRank
{ get; set; }
}
/*-------------------------END OF PLAYER CLASS--------------------------------------*/


 


/*-------------------------START OF TEAM CLASS---------------------------------------*/
public class Team : Player
{
//Variable Declarations
int spaceCounter, teamScore;
string teamName;
bool isGoodValue;
//Team object has an array of 4 Player objects
public Player[] teamPlayer = new Player[4];


//GET/SET For teamName variable
public string TeamName
{
get
{
return teamName;
}
set
{
spaceCounter = 0;
for (int j = 0; j < value.Length; j++)
{
if (char.IsSeparator(value, j))
++spaceCounter;
}
if ((value.Length == 0) || (spaceCounter == value.Length))
throw (new Exception("\nYou did not enter a valid Team name.....Please try again.\n"));
teamName = value;
}
}


//GET/SET For teamRank variable
public int TeamRank
{ get; set; }
Golfer teamMember = new Golfer();
int counter = 1;
private void CalculateTeamMemberRankings()
{
foreach (Team team in myTeams)
{
// Sort Team members on best score
team.Players.Sort(delegate(Golfer p1, Golfer p2)
{
return p1.Score().CompareTo(p2.Score());
});


// Set rank on team based on position in list
foreach (Golfer golfer in team.Players)
{
golfer.RankOnTeam = counter;
counter++;
}
// Reset counter for next teams ranking
counter = 1;
}
} // End CalculateTeamMemberRankings method



//GET/SET For teamScore variable
public int TeamScore
{
get
{
int sumOfScores = 0;


for (int n = 0; n < this.teamPlayer.Length; ++n)
{
sumOfScores += this.teamPlayer[n].LastGameScore;
}


this.teamScore = sumOfScores / this.teamPlayer.Length;
return teamScore;
}
}


//FUNCTION GetLeagueInfo() - Passes an array of Team - params for variable array
public void GetLeagueInfo(params Team[] golfTeam)
{
//Local Variable tmpTeamName
string tmpTeamName;


//WHILE LOOP - While isGoodValue=false
//INPUT FOR TEAM NAME
while (!isGoodValue)
{
//TRY/CATCH BLOCK - Catches improper input in team name
try
{
//Output and input to gather Team Name (sets tmpTeamName)
Console.Write("Enter Golf Team Name: ");
tmpTeamName = Console.ReadLine();


//FOR LOOP - Scans the golfTeam array passed into the function for duplicates of team name
for (int f = 0; f < golfTeam.Length; ++f)
{
//If the name is XXXXX XXXXX it throws an exception
if (Equals(tmpTeamName, golfTeam[f].TeamName))
throw (new Exception("Sorry, the Team Name is XXXXX XXXXX"));
}


//If no errors and no duplicates, TeamName is XXXXX XXXXX tmpTeamName
this.TeamName = tmpTeamName;
//Sets isGoodValue=true to terminate WHILE LOOP
isGoodValue = true;
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}//END OF WHILE LOOP


//FOR LOOP FOR PLAYER INFORMATION
for (int n = 0; n < this.teamPlayer.Length; ++n)
{
//isGoodValue is reset to false to initiate next while loop
isGoodValue = false;
//Creates a new Player object in the array
this.teamPlayer[n] = new Player();


//WHILE LOOP - While isGoodValue=false
//INPUT FOR FIRST HAME
while (!isGoodValue)
{
try
{
Console.Write("\nEnter a First Name for Player #{0} of Team {1}: ", n + 1, this.TeamName);
this.teamPlayer[n].FirstName = Console.ReadLine();
isGoodValue = true;
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}//END WHILE LOOP


//isGoodValue is reset to false to initiate next while loop
isGoodValue = false;


//WHILE LOOP - While isGoodValue=false
//INPUT FOR LAST NAME
while (!isGoodValue)
{
try
{
Console.Write("Enter a Last Name for Player #{0} of Team {1}: ", n + 1, this.TeamName);
this.teamPlayer[n].LastName = Console.ReadLine();
isGoodValue = true;
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}


}//END WHILE LOOP


//isGoodValue is reset to false to initiate next while loop
isGoodValue = false;


//WHILE LOOP - While isGoodValue=false
//INPUT FOR HANDICAP
while (!isGoodValue)
{
try
{
Console.Write("Enter a handicap for Player #{0} of Team {1}: ", n + 1, this.TeamName);
this.teamPlayer[n].Handicap = Convert.ToDouble(Console.ReadLine());
isGoodValue = true;
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}//END WHILE LOOP


//isGoodValue is reset to false to initiate next while loop
isGoodValue = false;


//WHILE LOOP - While isGoodValue=false
//INPUT FOR LAST GAME SCORE
while (!isGoodValue)
{
try
{
Console.Write("Enter the last game score for Player #{0} of Team {1}: ", n + 1, this.TeamName);
this.teamPlayer[n].LastGameScore = Convert.ToInt32(Console.ReadLine());
isGoodValue = true;
}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}//END WHILE LOOP


//isGoodValue is reset to false to initiate next while loop
isGoodValue = false;


//WHILE LOOP - While isGoodValue=false
//INPUT FOR PLAYER RANK
while (!isGoodValue)
{
try
{
Console.Write("Enter the team rank for Player #{0} of Team {1} (1-{2}): ", n + 1, this.TeamName, this.teamPlayer.Length);
this.teamPlayer[n].PlayerTeamRank = Convert.ToInt32(Console.ReadLine());
if ((this.teamPlayer[n].PlayerTeamRank > this.teamPlayer.Length) || (this.teamPlayer[n].PlayerTeamRank == 0))
throw (new Exception("\nYou did not enter a valid team ranking. Please try again.\n"));
for (int f = 0; f < n; ++f)
{
if (Equals(this.teamPlayer[n].PlayerTeamRank, this.teamPlayer[f].PlayerTeamRank))
throw (new Exception("Sorry, the Players Team Rank is a duplicate."));
}
isGoodValue = true;


}
catch (Exception error)
{
Console.WriteLine(error.Message);
}
}//END OF WHILE LOOP


}//END OF FOR LOOP FOR INPUTTING PLAYER INFO


}//END OF GETLEAGUEINFO() FUNCTION
}
/*-------------------------END OF TEAM CLASS--------------------------------------*/


 


/*-------------------------START OF GOLFERS CLASS--------------------------------------*/
public class Golfers
{
public static void Main()
{
//Variable declaration
//Creating a new Team array with 10 teams
Team[] golfTeam = new Team[10];
//Default option is y
char option = 'y';


//FOR LOOP - Will allow players to be added to the golfTeam array until 10 teams have been entered
for (int i = 0; i < golfTeam.Length; ++i)
{
//While the option=y (default is y) run through, will be able to set to 'n' to indicate team entry is finished
while (option == 'y')
{
//At position i in golfTeam, create a new Team object
golfTeam = new Team();
//Call the golfTeam function GetLeagueInfo() using the golfTeam object
golfTeam.GetLeagueInfo(golfTeam);
//Default value of local variable isGoodValue=false
bool isGoodValue = false;


//While isGoodValue is not true this loop will run
//As the default is false, after the team information is entered this loop will initiate
while (!isGoodValue)
{
//TRY/CATCH BLOCK - Prompts if a new Team is desired
try
{
Console.Write("\n\nEnter another Team (y/n): ");


//Will parse the input into a char format, and overwrite the option variable
char.TryParse(Console.ReadLine(), out option);


//Converting value of initial to lowercase to make comparison easier.
option = char.ToLower(option);


//IF/ELSE BLOCK - If the value is not n OR y, it will throw an exception at which point the loop will restart
//ELSE if the input IS n OR y, the isGoodValue variable will set to true and loop will terminate
if (option != 'n' && option != 'y')
throw (new Exception("\nYou entered an incorrect option"));
else
isGoodValue = true;
}
//If other exceptions are caught(numbers etc.) this catch clause will catch the exception
catch (Exception error)
{
Console.WriteLine(error.Message);
}


}//END OF SECOND WHILE LOOP


}//END OF INITIAL WHILE LOOP


}//END OF INITIAL LOOP


Console.ReadLine();
}//END OF MAIN()


}//END OF CLASS DECLARATION
/*-------------------------END OF GOLFERS CLASS--------------------------------------*/


}


Can you just fix here to have delegate to sort either by team name or player or team rank.

Expert:  Raj replied 1 year ago.
When you select the option 4.
The program exits.

Then check the following path.
Inside project folder go to folder bin inside that go to debug and there you will find the file with name Golf_Team.txt containing the team and its players organized/sorted
Customer: replied 1 year ago.
Yes. But I need something like in the above code. You can run it and see it.if you help me to sort with any team name or rank or score with delegates.Thanks.
Customer: replied 1 year ago.
Raj, can you put delegate in your code?
Customer: replied 1 year ago.
I am about to give you ex. Rating. Before that, can you implement delegate concept in your code?thanks.
Expert:  Raj replied 1 year ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.
Raj, Engineer
Category: Homework
Satisfied Customers: 1259
Experience: 4 + Experiance in IT Industry
Raj and 4 other Homework Specialists are ready to help you
Customer: replied 1 year ago.
I just rated it.But, I am outside.i might ask you more about delegates after I reach home this afternoon and compile it again.Thanks.
Expert:  Raj replied 1 year ago.
No problem. When ever I get time I will reply but sometimes it might be late response if I am working at any project in my company

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience
 
 
 

Related Homework Questions