none
Need help building classes with constructors, properties, methods etc. RRS feed

  • Question

  • This is not a project or solution or anything but I'm trying to learn how to build classes with constructors, properties, methods etc. This is what I have so far to start with but I feel like I need little more in the Vehicle class to make this class a little more complete. If someone could assist me on what I need to add to this class from what I have now.

    Vehicle class

    public class Vehicle
        {
    
            private int wins = 0;
            private int loses = 0;
            
            /// <summary>
            /// Constructor takes one argument for name.
            /// </summary>
            /// <param name="name"></param>
            public Vehicle(string name)
            {
                Name = name;
            }
    
            /// Property that has type driver, driver represents the driver of the vehicle.
            public string Name { get; set; }
    
            /// <summary>
            /// Public method named StartRace. Returns void, takes integer. Starts race when called.
            /// </summary>
            /// <param name="laps"></param>
            public void StartRace(int laps)
            {
                /// Winner gets to more than 200 laps, if not you lose.
                if (laps > 200)
                    wins++;
                else
                    loses++;
    
            }
        }

    Driver class

    namespace RaceTrack
    {
        /// <summary>
        ///Driver is class type. This driver will drive vehicle.
        /// </summary>
        public class Driver
        {
    
            public int Id { get; set; }
            public string Name { get; set; }
        }
    }

    What can I add to the Vehicle class besides what I already have? 

    Do I need to have  a seperate Race class and have it keep track of all the vehicles?  Do I need to have a Driver class-Vehicle class relationship? How code I do all of this?

    Wednesday, November 13, 2019 1:49 AM

All replies

  • This is clearly not a question about the Small Basic language.

    Try to find a forum dedicated to your language.


    Jan [ WhTurner ] The Netherlands

    Wednesday, November 13, 2019 9:26 AM
    Answerer