Create a class named Game that contains a string with the name of the Game and an integer that holds the maximum number of players. Include properties with get and set accessors for each field. Also, include a ToString () Game method that overrides the Object class’s ToString () method and returns a string that contains the name of the class (using GetType()), the name of the Game, and the number of players. Create a child class named GameWithTimeLimit that includes an integer time limit in minutes and a property that contains get and set accessors for the field. Write a program that instantiates an object of each class and demonstrates all the methods.
using System;
public class GameDemo
{
public static void Main()
{
Game baseball = new Game();
GameWithTimeLimit football = new GameWithTimeLimit();
baseball.Name = "baseball";
baseball.MaxNumPlayers = 9;
football.Name = "football";
football.MaxNumPlayers = 11;
football.Minutes = 60;
Console.WriteLine(baseball.ToString());
Console.WriteLine(football.ToString() + "Time to play = " + football.Minutes + " minutes");
}
}
public class Game
{
public string Name { get; set; }
public int MaxNumPlayers { get; set; }
public new string ToString()
{
return (GetType() + "" + Name + "maximum number of players = " + MaxNumPlayers);
}
}
public class GameWithTimeLimit : Game
{
public int Minutes { get; set; }
}
Getting a few errors:
1. 'Game.Name get and set' must declare a body because it is not marked abstract or extern.
2. 'Game.MaxNumPlayers get and set' must declare a body because it is not marked abstract or extern.
3. 'GameWithTimeLimit get and set' must declare a body because it is not marked abstract or extern.
Stress and don't know what to do. Please Help.