Hello guys it my first time trying c# i am trying to solve this problem and this is what i got so far i dont know where to locate the auto implementation properties to which class i a little bit confused appreciate any help

the question is add below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        public String gameName;
        public int maxPlayer;  



        static void Main(string[] args)
        {


        }
        public override string ToString()
        {
            return (GetType() + "" + gameName +"" + maxPlayer );
        }
        class GameWithTimeLimit : Game
        { 
        
        }


    }
}
Attachments Screen_shot_2011-04-07_at_5.16_.55_PM_.png 24.41 KB

1) Create a class named "Game"
2) Add two auto-implemented properties "Name" and "MaxPlayers"
3) Override the ToString() method. Make it return the class name (from GetType()), the game name (from the property above), and maximum number of players (from the other property above).
4) Create a child class of "Game" named "GameWithTimeLimit).
5) Add an auto-implementd property "GameTimeLimit"
6) Write a program that creates a "Game" object and a "GameWithTimeLimit" object
7) Use each of the properties and call ToString() on both the objects. Use Console to output the information so you can see what it does.
8) Save the file as GameDemo.cs

Comments
subtle and effective!

Something like this ??

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        static void Main(string[] args)
        {
            Game gameName1 = new Game();
            Game maxPlayer1 = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            gameName1.GameName = "Soccer";
            maxPlayer1.maxPlayer = 11;
            time.GameTimeLimit = 120;

            Console.Write("The name of the game is: {0}" + "\n" + "and the max num of players is: {1}" + "\n"+ "Game time limit is  {2}" + " minutes "+ "\n", gameName1.GameName, maxPlayer1.maxPlayer, time.GameTimeLimit);


        }


        private String gameName;
        protected int maxPlayer;

        public String GameName
        {
            get { return gameName; }

            set { gameName = value; }
        }
        public int MaxPlayer
        {
            get
            { return maxPlayer; }
            set { maxPlayer = value; }
        }


        public override string ToString()
        {
            return (GetType() + ": " + GameName + ": " + MaxPlayer);
        }
        class GameWithTimeLimit : Game
        {
            private int gameTimeLimit;
            public int GameTimeLimit
            {
                get
                {
                    return gameTimeLimit;
                }
                set
                {
                    gameTimeLimit = value;
                   
                }



                //timelimit
                //in minutes
            }


        }
    }
}

Close. Only create 2 objects, one of Game the other of GameWithTimeLimit. Set the properties then use ToString() to display the information about them (instead of using the properties directly).

Use auto-implemented properties, not ones where you have to code the get/set methods.

Format your ToString() method better, it will look ugly when you actually use it.

i got confused can you guide me through

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        static void Main(string[] args)
        {
            Game game1 = new Game();
           // Game maxPlayer1 = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
          //  gameName1.GameName = "Soccer";
          //  maxPlayer1.maxPlayer = 11;
            time.GameTimeLimit = 90;

           //// Console.Write("The name of the game is: {0}" + "\n" +
            //    "and the maximum number of players allowed is: {1}" + "\n" +
            //    "Game time limit is  {2}" + " minutes " + "\n",
            //    game1.GameName, game1.maxPlayer, time.GameTimeLimit);
        }


        //private String gameName;
       // protected int maxPlayer;

        public String GameName
        {get; set;}
         //   get { return gameName; }

         //   set { gameName = value; }
      //  }
        public int MaxPlayer
        {get; set;}
            //get
            //{ return maxPlayer; }
            //set { maxPlayer = value; }
        //}


        public override string ToString()
        {
            return (GetType() + "Game Name: " + GameName + ": " + MaxPlayer);
        }
        class GameWithTimeLimit : Game
        {
          //  private int gameTimeLimit;
            public int GameTimeLimit
            {get; set;}
            //    get{return gameTimeLimit;}
            //   set{gameTimeLimit = value;}

            //}

        }
    }
}

In your main method, set all the properties of game1 and time. Then add at the end

Console.WriteLine(game1.ToString());
Console.WriteLine(time.ToString());

You can delete all your comments.

You'll find that you'll want to add one more space in your ToString() method, you'll figure it out once you see the output.

i see in the output the name of the class


gamesDemo. Game
gamesDemo.Game+GameWithTimeLimit
Game Name:
Max Number of players:
Time in minutes

how can i fix it

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        static void Main(string[] args)
        {
            Game game1 = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            game1.GameName = "Soccer";
            game1.MaxPlayer = 11;
            time.GameTimeLimit = 90;
            Console.WriteLine(game1.ToString());
            Console.WriteLine(time.ToString());


        }


        public String GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }


        class GameWithTimeLimit : Game
        {
            public int GameTimeLimit
            { get; set; }





            public override string ToString()
            {
                return (GetType() + "\nGame Name: " + "\n" + "Max number of player: "  + "\n" + "Time in minutes: "  + "\n");
            }
        }
    }
}

i see in the output the name of the class


gamesDemo. Game
gamesDemo.Game+GameWithTimeLimit
Game Name:
Max Number of players:
Time in minutes

how can i fix it

Why did you change the ToString() method? It was almost correct then you made a major change that no longer has anything to do with the problem statement.

it still shows me the same thing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        public static void Main(string[] args)
        {
            Game game1  = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            game1.GameName = "Soccer";
            game1.MaxPlayer = 11;
            time.GameTimeLimit = 90;
            Console.WriteLine(game1.ToString());
            Console.WriteLine(time.ToString());  
        }
       
        public String GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }


        public override string ToString()
        {
            return (GetType()+"\nGame name: "+ GameName+"\n"+"Max player: "+  MaxPlayer + "\n");
        }

        class GameWithTimeLimit : Game
        { 
            public int GameTimeLimit
            { get; set; }   
       
        }

      

    }
}
Attachments Capture.PNG 37.59 KB

Which is what the problem statement asked you to show (except you forgot something in the GameWithTimeLimit ToString() method, namely the time limit).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    class Game
    {
        public static void Main(string[] args)
        {
            Game game1  = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            game1.GameName = "Soccer";
            game1.MaxPlayer = 11;
            time.GameTimeLimit = 90;
            Console.Write(game1.ToString());
            Console.WriteLine(time.GameTimeLimit.ToString());
         
        }
       
        public String GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }


        public override string ToString()
        {
            return (GetType()+"\nGame name: "+ GameName+"\n"+"Max player: "+ MaxPlayer + "\n"+ "Game Time Limit: ");
        }

        class GameWithTimeLimit : Game
        { 
            public int GameTimeLimit
            { get; set; } 
       
        }

      

    }
}

This is my output how is it now, serve its purpose

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    public class Game
    {
        public static void Main(string[] args)
        {
          Game gameOne  = new Game();
          GameWithTimeLimit time = new GameWithTimeLimit();
          gameOne.GameName = "Soccer";
          gameOne.MaxPlayer = 11;
          time.GameTimeLimit = 90;
          Console.Write(gameOne.ToString());
          Console.WriteLine(time.ToString()); 
        }
        public string GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }

        public override string ToString()
        {
            return (GetType()+ "\n\nGame name: "+ GameName+"\n\n"+"Max player: "+ MaxPlayer.ToString()+"\n\n");
        }

        class GameWithTimeLimit : Game
        { 
            public int GameTimeLimit
            { get; set; } 
        }

      

    }
}
Attachments Capture.PNG 25.47 KB

i need to write a console.write in the time limit?, or change the time.tostring, to time.gametimelimit.tostring?
i did that and he gave me everything, but it didn't gave me the child class is that o.k?

You need to add the method ToString() to your GameWithTimeLimit class and output all the properties that it has.

i assume it suppose to be like this?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    public class Game
    {
        public static void Main(string[] args)
        {
            Game gameOne = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            gameOne.GameName = "Soccer";
            gameOne.MaxPlayer = 11;
            time.GameTimeLimit= "90";
            Console.Write(gameOne.ToString());
            Console.WriteLine(time.ToString());


        }
        public string GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }

        public override string ToString()
        {
            return (GetType() + "\n\nGame name: " + GameName + "\n\n" + "Max player: " + MaxPlayer.ToString() + "\n\n");
        }

        class GameWithTimeLimit : Game
        {
            public string GameTimeLimit
            { get; set; }

            public override string ToString()
            {
                return (GetType() + "\n\nGame Time limit: "+ GameTimeLimit+ "\n\n");
            }
        }




    }
}

if you can tell me how can i show the max number of players i will appreciate it

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    public class Game
    {
        public static void Main(string[] args)
        {
            Game gameOne = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            gameOne.GameName = "Soccer";
            gameOne.MaxPlayer = 11;
            time.GameTimeLimit= "90";
            Console.Write(gameOne.ToString());
            Console.WriteLine(time.ToString());


        }
        public string GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }

        public override string ToString()
        {
            return (GetType() + "\n\nGame name: " + GameName + "\n\n" + "Max player: " + MaxPlayer.ToString() + "\n\n");
        }

        class GameWithTimeLimit : Game
        {
            public string GameTimeLimit
            { get; set; }

            public override string ToString()
            {
                return (GetType() + "\n\nGame Time limit: " + GameTimeLimit + "\n\n" + "Max player: " + MaxPlayer.ToString() + "\n\n");

            }
        }




    }
}
Attachments Capture.PNG 43.14 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gamesDemo
{
    public class Game
    {
        public static void Main(string[] args)
        {
            Game gameOne = new Game();
            GameWithTimeLimit time = new GameWithTimeLimit();
            gameOne.GameName = "Soccer";
            gameOne.MaxPlayer = 11;
            time.GameTimeLimit = 90 ;
            time.MaxPlayer= 11;
            Console.WriteLine(gameOne.ToString());
            Console.WriteLine(time.ToString());
      


        }
        public string GameName
        { get; set; }

        public int MaxPlayer
        { get; set; }

        public override string ToString()
        {
            return (GetType() + "\n\nGame name: " + GameName + "\n\n" + "Max player: " + MaxPlayer.ToString() + "\n\n");
        }

        class GameWithTimeLimit : Game
        {
            public int GameTimeLimit
            { get; set; }

            public override string ToString()
            {
                return (GetType() + "\n\nGame Time limit: " + GameTimeLimit + "\n\n" + "Max player: " + MaxPlayer + "\n\n");

            }
        }




    }
}
This question has already been answered. Start a new discussion instead.