Ejemplo n.º 1
0
		static void Main(string[] args)
		{
			Car car1 = null;
			car1 = new Car();

			car1.Name = "car1";
			car1.Cylinders = 4;
			car1.Colour = "Blue";
			car1.Doors = 4;
			car1.Display();

			Car car2 = new Car();

			car2.Name = "car2";
			car2.Cylinders = 6;
			car2.Colour = "Red";
			car2.Doors = 2;
			car2.Display();



			Console.ReadKey();


		}
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // create a new car object
            Car car = new Car();
            car.PrintData();
            car.Model = "Merseedes V5";
            car.Color = "Black";
            car.Engine = 3.2;
            car.DoorCount = 9;
            car.Accelerate();
            car.PrintData();

            //create another car object
            string model = "Vormula";
            Car car2 = new Car(model);
            car2.PrintData();
            car2.Color = "Green";
            car2.Engine = 2.1;
            car2.DoorCount = 4;
            car2.FuzzyDice = false;
            car2.Brake();
            car2.PrintData();

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
           // Context db = new Context(ConfigurationManager.ConnectionStrings["ConnectionCarList"].ConnectionString);

            string CS = @"data source=(localdb)\v11.0;AttachDBFileName=D:\daa\First.mdf;Integrated Security=true;";
            Context db = new Context(CS);

            Car car = new Car() { Name = "BMW", Fuel = 50, Url = "car_url" };
            db.Cars.Add(car);
            db.SaveChanges();

            foreach (var item in db.Cars)
            {
                Console.WriteLine("{0}{1}", item.Name, item.Fuel);
            }

            Console.ReadKey();

        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Car mycar = new Car();
            mycar.currentSpeed = 20;
            mycar.petName = "Tigran";
            for (int i = 0; i < 10; i++)
            {
                mycar.SpeedUp(5);
                mycar.PrintState();
            }
            Car c = new Car();
            c.PrintState();

            Motorcycle mc = new Motorcycle(5);
            mc.name = "armen";
            mc.Uraa();
            Console.WriteLine($"Driver is name {mc.name}");

            Motorcycle mot = new Motorcycle("arturik");
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //create a person object
            Person josh = new Person("Josh", 26, 130);

            //create our cars inventory
            List<Car> carInventory = new List<Car>();

            //create cities
            List<City> cities = new List<City>();

            City city1 = new City("New York City", 100);
            City city2 = new City("Chicago", 200);

            cities.Add(city1);
            cities.Add(city2);

            //add cars to the inventory
            Car car1 = new Car("volkswagon", "gti", 2015, 25000);
            Car car2 = new Car("mazda", "3", 2014, 20000);
            Car car3 = new Car("subaru", "impreza", 2015, 23000);

            carInventory.Add(car1);
            carInventory.Add(car2);
            carInventory.Add(car3);

            //invoke methods on the person object
            josh.personInfo();
            josh.workOut(50);

            //josh.buyCar("Volkswagon", "GTI", carInventory);
            josh.buyCar("3", "Mazda", carInventory);
            josh.viewCars();
            //josh.driveCar("Mazda", "3", cities, "Chicago");
            josh.driveCar("Mazda", "3", cities, "New York City");

            Console.ReadLine();
        }
Ejemplo n.º 6
0
        static void Main()
        {
            Car newCar = new Car();
            newCar.car = '@';
            newCar.color = ConsoleColor.Blue;
            newCar.x = 4;
            newCar.y = 10;

            Console.BufferHeight = Console.WindowHeight = 20;
            Console.BufferWidth = Console.WindowWidth = 30;
            int i = 0;
            int j = 3;
            int k = 4;
            var random = new Random();
            while (true)
            {

                if (i <= 19)
                {
                     positonCar(j,i++,'B');
                    positonCar(k, i, 'V',ConsoleColor.Green);
                    if (i == 19)
                    {
                        i = 0;
                        j = random.Next(10);

                    }
                }

               // positonCar(random.Next(0,10),random.Next(0,10),'B');
                positonCar(newCar.x, newCar.y, newCar.car, newCar.color);
                Thread.Sleep(200);
                Console.Clear();

            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {

            GetCarsMap();

            return;


            HtmlNodeCollection nodes;
            var errorCnt = 0;
            //var loadOnlyThatBrands = args;
            //string[] loadOnlyThatBrands = {"Honda"};

            args = new[] { "Honda" };

            try
            {
                var downloadedBrandsJson = File.ReadAllText("downloadedbrands.json");
                if (!string.IsNullOrEmpty(downloadedBrandsJson))
                {
                    skipBrands = JsonConvert.DeserializeObject<List<string>>(downloadedBrandsJson);
                }





                var brandsUrl = "http://auto.ria.com/map/bu/";
                HtmlDocument doc = HtmlHelper.GetHtmlDocument(brandsUrl, ref _totalDownloadDataSize);
                var brandsPages = HtmlHelper.GetPages(doc);















                var brands = HtmlHelper.GetBrands(doc);

                foreach (var brand in brands.Where(b => !skipBrands.Contains(b.Value) && (args.Length == 0 || args.Contains(b.Value))))
                {
                    List<Car> carsByBrand = new List<Car>();

                    doc = HtmlHelper.GetHtmlDocument(brand.Key, ref _totalDownloadDataSize);
                    var modelsPages = HtmlHelper.GetPages(doc);


                    Dictionary<string, string> models = HtmlHelper.GetModels(doc);

                    var modelcount = 0;
                    foreach (var model in models)
                    {
                        List<Car> carsByBrandAndModel = new List<Car>();
                        modelcount++;
                        doc = HtmlHelper.GetHtmlDocument(model.Key, ref _totalDownloadDataSize);
                        Dictionary<string, string> cars = HtmlHelper.GetCars(doc);

                        var carcount = 0;
                        try
                        {

                            foreach (var car in cars)
                            {
                                carcount++;
                                var realCar = new Car
                                {
                                    attributes = new Dictionary<string, string>(),
                                    imagesUrl = new List<string>(),
                                    url = car.Key,
                                    brand = brand.Value,
                                    model = model.Value
                                };

                                doc = HtmlHelper.GetHtmlDocument(car.Key, ref _totalDownloadDataSize);
                                HtmlNode node = doc.DocumentNode.SelectSingleNode("//h1[@class='head-cars']");

                                // year
                                if (node != null && node.InnerHtml != null)
                                {
                                    var year = node.SelectSingleNode("//span[@class='year']");
                                    realCar.year = year.InnerText;
                                }

                                if (node != null && node.InnerText != null)
                                {
                                    realCar.modelFull = _trimmer.Replace(node.InnerText.Replace("\n", ""), " ").Trim();
                                }

                                // price
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='price-seller']");
                                if (node != null && node.InnerHtml != null)
                                {
                                    var price = node.SelectSingleNode("//span[@class='price']");
                                    realCar.priceSeller = price.InnerText;
                                }

                                // price-at-rate
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='price-at-rate']");
                                if (node != null && node.InnerText != null)
                                {
                                    realCar.priceAtRate = _trimmer.Replace(node.InnerText.Replace("\n", ""), " ").Trim();
                                }


                                // read attributes
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='characteristic delimeter']");
                                if (node != null)
                                {
                                    nodes = node.SelectNodes(".//p[@class='item-param']");
                                    if (nodes != null)
                                    {
                                        HtmlHelper.ReadCarAttributes(ref realCar, nodes);
                                    }
                                }

                                // read attributes
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='box-panel rocon']");
                                if (node != null)
                                {
                                    node = node.SelectSingleNode(".//dl[@class='unordered-list']");
                                    if (node != null)
                                    {
                                        nodes = node.SelectNodes(".//dd");
                                        if (nodes != null)
                                        {
                                            HtmlHelper.ReadCarAttributes(ref realCar, nodes);
                                        }
                                    }
                                }

                                // read attributes
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='box-panel rocon']");
                                if (node != null)
                                {
                                    nodes = node.SelectNodes(".//p[@class='additional-data']");
                                    if (nodes != null)
                                    {
                                        HtmlHelper.ReadCarAttributes(ref realCar, nodes, true);
                                    }
                                }


                                // read description
                                node = doc.DocumentNode.SelectSingleNode("//div[@class='box-panel rocon']");
                                if (node != null)
                                {
                                    node = node.SelectSingleNode(".//p[@id='description']");
                                    if (node != null && node.InnerHtml != null)
                                    {
                                        realCar.description = node.InnerHtml;
                                    }
                                }

                                // read car id and date added
                                nodes = doc.DocumentNode.SelectNodes("//p[@class='item-param']");
                                if (nodes != null)
                                {
                                    foreach (var n in nodes)
                                    {
                                        if (n.InnerHtml != null)
                                        {
                                            if (n.InnerHtml.Contains("icon-id-item"))
                                            {
                                                var s = n.SelectSingleNode(".//strong");
                                                if (s != null)
                                                {
                                                    var value = _trimmer.Replace(s.InnerText.Replace("\n", ""), " ").Trim();
                                                    realCar.carId = value;
                                                }
                                            }
                                            else if (n.InnerHtml.Contains("final_page__add_date"))
                                            {
                                                var s = n.SelectSingleNode(".//strong");
                                                if (s != null)
                                                {
                                                    var value = _trimmer.Replace(s.InnerText.Replace("\n", ""), " ").Trim();
                                                    realCar.dateAdded = value;
                                                }
                                            }
                                        }
                                    }
                                }

                                // read photos
                                if (realCar.carId != null)
                                {
                                    var photolink = "http://auto.ria.com/old/auto_photo/megaphoto/" + realCar.carId + "/";

                                    doc = HtmlHelper.GetHtmlDocument(photolink, ref _totalDownloadDataSize);

                                    node = doc.DocumentNode.SelectSingleNode("//script[@type='text/javascript']");
                                    //nodes = doc.DocumentNode.SelectNodes("//a");

                                    if (node != null && node.InnerHtml != null && node.InnerHtml.Contains("window.Ria.Auto.AutoId"))
                                    {

                                        var xxx = node.InnerHtml.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

                                        var key1 = "window.Ria =";
                                        var value1 = xxx[0].Substring(xxx[0].IndexOf(key1, StringComparison.OrdinalIgnoreCase) + key1.Length).Trim();
                                        value1 = _trimmer.Replace(value1.Replace("\n", ""), " ").Trim();
                                        var obj1 = JsonConvert.DeserializeObject<Ria>(value1);


                                        var key2 = "window.Ria.Auto.AutoId = ";
                                        var value2 = xxx[1].Substring(xxx[1].IndexOf(key2, StringComparison.OrdinalIgnoreCase) + key2.Length).Trim();
                                        value2 = _trimmer.Replace(value2.Replace("\n", ""), " ").Trim();

                                        var key3 = "window.Ria.Auto.PhotoData =";
                                        var value3 = xxx[3].Substring(xxx[3].IndexOf(key3, StringComparison.OrdinalIgnoreCase) + key3.Length).Trim();
                                        value3 = _trimmer.Replace(value3.Replace("\n", ""), " ").Trim();
                                        var obj3 = JsonConvert.DeserializeObject<PhotoData>("{photoDataItems:" + value3 + "}");


                                        foreach (var item in obj3.photoDataItems)
                                        {
                                            if (item.url.EndsWith(".jpg"))
                                            {
                                                item.url = item.url.Replace(".jpg", "fx.jpg");
                                            }
                                            if (item.url.EndsWith(".png"))
                                            {
                                                item.url = item.url.Replace(".jpg", "fx.png");
                                            }
                                            if (item.url.EndsWith(".jpeg"))
                                            {
                                                item.url = item.url.Replace(".jpeg", "fx.jpeg");
                                            }
                                            if (item.url.EndsWith(".gif"))
                                            {
                                                item.url = item.url.Replace(".gif", "fx.gif");
                                            }

                                            realCar.imagesUrl.Add("https://cdn.riastatic.com/photos/" + item.url);
                                        }
                                    }
                                }

                                carsByBrand.Add(realCar);
                                carsByBrandAndModel.Add(realCar);

                                Console.Clear();
                                Console.WriteLine("brand:{0} model:{1}  model {4} of {5}  car {2} of {3} errors:{6} downloadSize:{7}MB, {8}GB", brand.Value, model.Value, carcount, cars.Count, modelcount, models.Count, errorCnt, Math.Round(_totalDownloadDataSize / 1024 / 1024, 1), Math.Round(_totalDownloadDataSize / 1024 / 1024 / 1024, 3));
                                Console.WriteLine(realCar);
                                Console.WriteLine("");

                                //Console.WriteLine("--- attributes ---");
                                //foreach (var attribute in realCar.attributes)
                                //{
                                //    Console.WriteLine(attribute.Key + " " + attribute.Value);
                                //}
                                //Console.WriteLine("------------------");
                                //Console.WriteLine("");
                                Console.WriteLine("--- description ---");
                                Console.WriteLine(realCar.description);
                                Console.WriteLine("-------------------");
                                //Console.WriteLine("");
                                Console.WriteLine("images:{0}", realCar.imagesUrl.Count);
                                //Console.WriteLine("--- images ---");
                                //foreach (var url in realCar.imagesUrl)
                                //{
                                //    Console.WriteLine(url);
                                //}
                                //Console.WriteLine("--------------");

                                //Console.WriteLine("");
                                //Console.WriteLine("");


                            }
                        }
                        catch (Exception ex)
                        {
                            errorCnt++;
                            Console.WriteLine(ex.Message);
                        }


                        // save cars by model 
                        SaveCarsToFile(carsByBrandAndModel, brand.Value, model.Value);
                    }

                    SaveCarsToFile(carsByBrand, brand.Value);
                    skipBrands.Add(brand.Value);

                    string json = JsonConvert.SerializeObject(skipBrands.ToArray());
                    System.IO.File.WriteAllText("downloadedbrands.json", json);
                }

            }
            catch (Exception ex)
            {
                Console.Write("ERROR! " + ex.Message);
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            string username = "******";
            string password = "******";

            Console.WriteLine("Hello " + username +", your password is :" + password);
            Console.WriteLine("New Password please:");
            password = Console.ReadLine();
            Console.WriteLine("Hello " + username + ", your new password is :" + password);
            Console.ReadLine();

            Car car;
            car = new Car("Red");
            Console.WriteLine(car.Describe());
            Console.WriteLine("The car getter method is exposed for color: " + car.Color);
            car.Color = "purple";
            Console.WriteLine("The car setter method is exposed for color: " + car.Color);

            Car car2 = new Car("Green");
            Console.WriteLine(car2.Describe());
            Console.ReadLine();

            GreetPersons(0);
            GreetPersons(25, "John", "Jane", "Tarzan");
            Console.ReadKey();

            int number1;
            do
            {
                Console.WriteLine("Please enter a number(1-10):");
                number1 = int.Parse(Console.ReadLine());
                if ((number1 > 0) && (number1 < 11))
                    Console.WriteLine("Good job!");
                else
                    Console.WriteLine("Out of range.. boo");

            } while ((number1 < 1) || (number1 > 10));

            int result = AddNumbers(number1);
            Console.WriteLine("Adding ?? to your number: " + result);
            Console.ReadLine();

            ArrayList list = new ArrayList();
            list.Add("John Doe");
            list.Add("Jane Doe");
            list.Add("Someone Else");

            foreach(string name in list)
                Console.WriteLine(name);

            Console.ReadLine();

            //Class with Public methods
            MyClass cls  = new MyClass();
            Console.Write("Write a number: ");
            long a= Convert.ToInt64(Console.ReadLine()); // a is the number given by the user
            long av = cls.volteado(a);
            bool isTrue = cls.siprimo(a);
            bool isavTrue = cls.siprimo(av);
            Console.WriteLine("a: " + a + "av: " + av);
            if (isTrue == false && isavTrue == false)
                Console.WriteLine("Both original and swapped numbers are prime.");
            else
                Console.WriteLine("One of the numbers isnt prime.");
            Console.ReadLine();

            Console.WriteLine("Do you enjoy C# ? (yes/no/maybe)");
            string input = Console.ReadLine();
            switch(input.ToLower())
            {
                case "yes":
                case "maybe":
                    Console.WriteLine("Great!");
                    break;
                case "no":
                    Console.WriteLine("Too bad!");
                    break;
                default:
                    Console.WriteLine("I'm sorry, I don't understand that!");
                    break;
            }

            Console.ReadLine();
        }
 static void Main(string[] args)
 {
     Car mycar = new Car();
     mycar.turnOnRadio(false);
     Console.ReadKey();
 }