I need help completing my Project. This is my requirement. The deadline is Tonight. You are going to code a program for a new golf league. The program will need to have the following: An array of a variable number of golf teams (max 10). Classes for the following: A Team class containing team name, an array of 4 Player objects, and scoring rank of team. A Player class containing first name, last name, handicap, score for last game and rank on team. 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. A sorted list of team information should be written to a file. 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
kathmandu09 · Feb 27, 2015 3:40 AM · 19,798 views
So where is ur code? And where r u stuck?
alece · Feb 27, 2015 8:10 AM
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 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
50L4r15 · Feb 27, 2015 8:58 AM
https://www.youtube.com/watch?... https://www.youtube.com/watch?...
michel · Feb 27, 2015 9:06 AM
Your code shows that you are trying to do it on Windows Form using Data Grid. It would be a lot easier for anybody to see and run the code if you share the solution as a zip file. Also, where did you stuck ? what're you trying to do but couldn't? And what you want help with ? Is it for everything that is listed on assignment or is there anything specific you want help with ( I saw that you have done something, but without running it I really can't help you) I will be online for few hours, so if you share the zip file I might able to help you. And one personal experience - I always waited until the last minute for everything and thus always have miserable consequences. Don't do that my friend.. Just my one cent advice. :)
uscis_pidit · Feb 27, 2015 11:10 AM
Here is my code so far. Im trying to do it on console. I can't attach my zip file. but here is my code. using GroupProject4; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GroupProject4 { public class Class { string firstName; string msg; string lastName; double handicap; int lastGameScore; static void Main(string[] args) { } //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--------------------------------------*/ }} public class Team : Class { //Variable Declarations int spaceCounter, teamScore; string teamName; bool isGoodValue; //Team object has an array of 4 Player objects 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 public IEnumerable<Team> myTeams { get; set; } public IEnumerable<Golfer> Players { get; set; } } /*-------------------------END OF TEAM 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 Class(); //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--------------------------------------*/ here is my error: Error 1 Expected class, delegate, enum, interface, or struct C:\Users\Subarna\Documents\Visual Studio 2013\Projects\GroupProject4\GroupProject4\Program.cs 96 16 GroupProject4 Error 2 Type or namespace definition, or end-of-file expected C:\Users\Subarna\Documents\Visual Studio 2013\Projects\GroupProject4\GroupProject4\Program.cs 100 2 GroupProject4 Error 3 Type or namespace definition, or end-of-file expected C:\Users\Subarna\Documents\Visual Studio 2013\Projects\GroupProject4\GroupProject4\Program.cs 100 3 GroupProject4 Thanks for responding. And thank you for ur advice.I really appreciate it.
kathmandu09 · Feb 27, 2015 12:34 PM
Honestly, all this code got me lost. It is impossible for me to find out the problem just looking at the code. To re-produce your error, I need to setup the exact forms, text box, data grid and event handlers and trust me it is just a very time consuming process. You can share the code via Google drive or any other cloud storage of your choice if you can't attach it here.
uscis_pidit · Feb 27, 2015 1:09 PM
Can you zip me your the code you have done plz..
kathmandu09 · Feb 27, 2015 1:23 PM
https://www.youtube.com/watch?... https://www.youtube.com/watch?... https://www.youtube.com/watch?... Training & Job Placement Note: If You Are Unable to Reach My Contact Number Then Please Send Your queries To My Mail ID Contact Number: 347 491 5246 Email: michleramds@gmail.com
michel · Mar 10, 2015 10:01 AM
I'd make a console application as the requirements do not state you have to do it in win forms.
kkus · Mar 15, 2015 8:56 AM
काठमाडौँ०९ ब्रो तपाई को प्रोग्राम एक दमै बग्गी छ ब्रो ! मैले १ घण्टा भन्दा बेसीटाइम भक्कर देको ! रिंगटा नै लाग्यो तपाई को प्रोग्राम दिबग गर्दा ! क्लास फाइलमा किन तपाई को मैन फंक्सन जब कि गोल्फ़रस क्लास मा तेही फंक्सन छ ? अल्सो क्लासको सत्ता अरु कहिँ नाम दिनुस ! नेमिंग कन्वेसन अनुसार ! एण्ड अफ फाइल एक्स्पेक्तेद भनेको इउ आर मिस्सिंग क्लोसिंग ब्रसेस } भनेको मान्नु हुन्छ भने दुइ वोटा सेप्रेट क्लास लैब्रारी क्रियेत गर्नु क्लास फाइल र टिम फाइललाइ ! अनि गोल्फ़र क्लास लै मेन कन्सोल एप्प बनौनुस ! तेस्पछि रेफेरेंस एड गर्नुस ! public IEnumerable<Golfer> Players { get; set; } गोल्फ़र तैप कहा दिक्लेर गर्न भाको छ ? Player[] teamPlayer = new Player[4]; प्लेयेर तैप कहाँ दिक्ल्रे गर्न भाको छ ? पुरानो धागो रहेछ ! आई दोन'त् नो येदि इउ ह्याब अलरेडी सल्भद द प्रब्लम अर नट !
Nas · Mar 15, 2015 10:46 AM
This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.
Start a New Discussion