Posted by: kathmandu09 February 27, 2015
C# Assignment
Login in to Rate this Post:     0       ?        
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.
    
          
      
 
Read Full Discussion Thread for this article