Skip to main content

C#: Program #41 (Oop6)

using System;


namespace Oop6
{
    class Program
    {
        static void Main(string[] args)
        {
            Vehicle Civic = new Vehicle(4,200,"Dinkeee");
            if (Civic is IDrivable)
            {
                Civic.Move();
                Civic.Stop();
            }
            else
            {
                Console.WriteLine("The {0} Cant be driven", Civic.Brand);
            }
            Console.ReadKey();
        }
    }
interface IDrivable
    {

        int Wheels { get; set;}
        double Speed { get; set; }
        void Move();
        void Stop();
    }
 class Vehicle:IDrivable
   
    {
        public string Brand { get; set;}
        public int Wheels{get; set;}
        public double Speed{get; set;}
        public Vehicle(int wheels=0,double speed=0,string brand="No Brand")
        {
            Brand = brand;
            Wheels = wheels;
            Speed = speed;
        }
        public void Move() {
            Console.WriteLine("The {0} moves at {1} MPH",Brand,Speed);

        }
        public void Stop() {
            Console.WriteLine("The {0} stoped", Brand);
            Speed = 0;
        }


    }


}

Comments

Popular posts from this blog

C#: Program #15 (For Loop)

using System; namespace Loops {     class Program     {         static void Main(string[] args)         {                         object[] information = {"Gray", "14-Arid-4052", "Rawalpindi",21,3.80};             for (int i = 0; i < information.Length; i++)             {                 Console.WriteLine("The value of index {0} is {1}",i,information[i]);             }                 Console.ReadKey();         }     } }