Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In C#, create a class named Game that contains a string with the name of the

ID: 3930871 • Letter: 1

Question

1. In C#, 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. Save the file as GameDemo.cs.

Explanation / Answer

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; }

}