static void Main(string[] args)
    {
        VolvoCar myCar = new VolvoCar("C30", "Black");

        Console.WriteLine("Car: {0}", myCar);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        // create a VolvoCar object and upcast it to object
        object myObject = new VolvoCar("Adam Freeman", "Black", 30, "Premium");

        // call the PrintCarDetails method and explicitly cast the
        // object in a single statement
        PrintCarDetails((Car)myObject);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        // create a new instance fof VolvoCar and upcast it to Car
        Car myCar = new VolvoCar("Adam Freeman", "Black", 30, "Premium");

        // call the CalculateFuelForTrip method and print out the result
        int result = myCar.CalculateFuelForTrip(1000);

        Console.WriteLine("Result: {0} gallons", result);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        // create an instance of VolvoCar
        VolvoCar myVolvo = new VolvoCar("Adam Freeman", "Black", 30, "Premium");

        // upcast from VolvoCar to Car
        Car myCar = myVolvo;

        // upcast from Car to object
        object myObject = myCar;

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Пример #5
0
 public ActionResult ShowVolvoDecsription(VolvoCar car)
 {
     if (car.Model == "S 60")
     {
         return(View("Volvo_S60"));
     }
     else if (car.Model == "XC 70")
     {
         return(View("Volvo_XC70"));
     }
     else
     {
         return(View("Volvo_S90"));
     }
 }
    static void Main(string[] args)
    {
        // create a VolvoCar object and upcast it to object
        object myObject = new VolvoCar("Adam Freeman", "Black", 30, "Premium");

        // perform an explicit cast of myObject to Car
        Car myCar = (Car)myObject;

        // read a field from the Car object
        Console.WriteLine("Owner: {0}", myCar.CarOwner);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Пример #7
0
    static void Main(string[] args)
    {
        // create a VolvoCar object
        VolvoCar myVolvo = new VolvoCar("Adam Freeman", "Black", 30, "Premium");

        // perform an implicit cast by upcasting
        Car myCar = myVolvo;

        // perform an implicit cast by calling a method
        // that takes a base type as a parameter
        PrintCarDetails(myVolvo);

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
    static void Main(string[] args)
    {
        //// create an instance of Car
        //Car myCar = new Car("Adam Freeman", "Black", 30);

        //// call the TripPrinter.PrintTripDetails method
        //TripPrinter printer = new TripPrinter();
        //printer.PrintTripDetails(myCar);

        //// create an instance of VolvoCar
        //VolvoCar myVolvo = new VolvoCar("Adam Freeman", "Black", 30, "High Performance");

        //// call the TripPrinter.PrintTripDetails method
        //TripPrinter printer = new TripPrinter();
        //printer.PrintTripDetails(myVolvo);

        Car myCar = new VolvoCar("Adam Freeman", "Black", 30, "High Performance");

        // wait for input before exiting
        Console.WriteLine("Press enter to finish");
        Console.ReadLine();
    }
Пример #9
0
        /// <summary>
        /// Generates a car. Logs to a console in case user specifies car make not correctly and 'Null' car is chosen.
        /// </summary>
        /// <param name="parameters">Parameters for requested car.</param>
        /// <returns>A Car. Can be a 'Null' Car.</returns>
        public Car ProvideCar(CarParameters parameters)
        {
            Car car = null;

            switch (parameters.CarMake)
            {
            case "opel":
                car = new OpelCar();
                break;

            case "stanley":
                car = new StanleyCar();
                break;

            case "volvo":
                car = new VolvoCar();
                break;

            default:
                car = new NullCar();
                Console.WriteLine("Logging: Possible problem, a null car is created");
                break;
            }

            if (!(car is NullCar))
            {
                switch (parameters.EngineRequested)
                {
                case "diesel":
                    car.Engine = new DieselEngine();
                    break;

                case "electric":
                    car.Engine = new ElectricEngine();
                    break;

                case "gasoline":
                    car.Engine = new GasolineEngine();
                    break;

                case "steam":
                    car.Engine = new SteamEngine();
                    break;

                default:
                    car.Engine = new NoneEngine();
                    break;
                }

                switch (parameters.PurposeRequested)
                {
                case "groceries":
                    car.Purpose = new GroceriesPurpose();
                    break;

                case "racing":
                    car.Purpose = new RacingPurpose();
                    break;

                default:
                    car.Purpose = new NoPurpose();
                    break;
                }
            }

            return(car);
        }
Пример #10
0
        static void Main()
        {
            Person myPerson = new Person("Jhonny");
            int    myCount  = 10;

            Console.WriteLine($"Variable values before are {myPerson.Name} and {myCount}");

            ProductCustomType pCT = new ProductCustomType();

            pCT.AnotherTestMethod(myPerson, myCount);

            Console.WriteLine($"Variable values after are {myPerson.Name} and {myCount}");

            Calculator calc          = new Calculator();
            int        ProductResult = calc.CalculateProduct(4, 6);
            int        SumResult     = calc.CalculateSum(8, 4);
            int        RatioResult   = calc.CalculateRatio(12, 6);

            Console.WriteLine($"Sum is {SumResult}, product is {ProductResult} and ratio is {RatioResult}");


            var CalculationResult = pCT.CalculateProduct(4, 6);

            Console.WriteLine(CalculationResult.Result);

            AnotherProduct anotherProduct = new AnotherProduct();

            anotherProduct.ItemsInStock = 20;
            anotherProduct.PricePerItem = 5;

            Console.WriteLine($"Total stock value is {anotherProduct.GetTotalValueOfStock()}");

            Goods product1 = new Goods("Laptop", "Emeka Alison");

            product1.ReadModifyQuantity();
            product1.itemsInStock = 20;
            product1.ReadModifyQuantity();

            TripPrinter printTrip = new TripPrinter();


            VolvoW30 myW30 = new VolvoW30("Nathan", "blue", 20, "Himax");

            myW30.PrintCarDetails();

            printTrip.PrintTripDetails(myW30);

            FordWisest myFordWisest = new FordWisest("Wisest", "green", 25, "Alloy reams");

            myFordWisest.PrintCarDetails();

            VolvoCar wisestVolvo = new VolvoCar("Chijioke", "red", 20, "wisest atmos");

            wisestVolvo.PrintCarDetails();
            int fuelRequired = wisestVolvo.CalculateFuelForTrip(300);

            Console.WriteLine($"Fuel required is {fuelRequired} gallons");

            //EngineSpec wisestEngine = new EngineSpec(250, "Six rings");

            //VolvoM30 wisestCar = new VolvoM30("Chijioke", "white", wisestEngine);
            //VolvoM30 yourCar = new VolvoM30("Onah", "black", wisestEngine);

            //Console.WriteLine(wisestCar.OwnerName);
            //Console.WriteLine(yourCar.OwnerName);
            //Console.WriteLine(yourCar.Engine.EngineCapacity);

            //NumberBaseConverter NBC = new NumberBaseConverter();
            //NBC.NumberConverter();
            //ArithmeticOperators ao = new ArithmeticOperators();
            //ao.ArithmeticOperations();
            //ExplicitConversion EC = new ExplicitConversion();
            //EC.ExplicitConverter();
            //Iteration repeat = new Iteration();
            //repeat.ForLoop();
            //repeat.ArrayLooping();
            //repeat.ArrayForEach();
            //repeat.DoWhile();
            //repeat.WhileLoop();

            //Comparison checker = new Comparison();
            //checker.Comparator();
            //checker.Selector();
            //checker.Switcher();
            //Console.WriteLine("Learning C# again.");
            //AnotherMethod();

            //Student firstStudent = new Student
            //{
            //    Id = 100,
            //    Name = "Chijioke"
            //};
            //firstStudent.Passmark = 35;

            //Console.WriteLine($"ID = {firstStudent.Id}, and Name = {firstStudent.Name} and Passmark = {firstStudent.Passmark}");

            //Customer customer = new Customer();
            //((ICustomer)customer).Print();
            //((ISecondCustomer)customer).Print();
        }