I'm a novice programmer. I've been writing scripts for about 9 to 11 weeks. Any how I have been buying books per the posting that alot of you guys have recommended. I'm trying to learn "OOP", and it can be little challenging. I have worked the exercises in back of the book. The first exercise told me to make a Console Application program that prompts the user for a type of sport, and the coaches name.
- My first question is, did I do this question right?
- Are there other ways of doing the same thing, but in different process?
- I do realize that I do not have any "try/catches", the exercise told me not to add to this exercise problem. So we will worry about this later.
My code:
static void Main(string[] args)
{
Sport sport01 = new Sport();
sport01.TypeOfSport = GetSportsName();
sport01.CoachesName = GetCoachesName();
Console.WriteLine();
Console.WriteLine(sport01.ToString());
System.Threading.Thread.Sleep(8000);
}
// Prompting user input for type of sport.
public static string GetSportsName()
{
string typeOfSport;
Console.Write("Enter Sports Name : ");
typeOfSport = Console.ReadLine();
return typeOfSport;
}
// Prompting user inout for coaches name.
public static string GetCoachesName()
{
string coachesName;
Console.Write("Enter Coaches Name : ");
coachesName = Console.ReadLine();
return coachesName;
}
class Sport
{
protected string typeOfSport;
protected string coachesName;
public Sport()
{
typeOfSport = "Not Given";
coachesName = "Not Given";
}
public Sport(string typeOS, string coachesN)
{
typeOfSport = typeOS;
coachesName = coachesN;
}
public string TypeOfSport
{
get { return typeOfSport; }
set { typeOfSport = value; }
}
public string CoachesName
{
get { return coachesName; }
set { coachesName = value; }
}
public override string ToString()
{
return "\n" + "\n" +
"\nSports Name : " + typeOfSport +
"\n" +
"\nCoaches Name : " + coachesName;
}
}