static void Main(string[] args) { Car car = new Car(); Bicycle bicycle = new Bicycle(); car.Ride(); car.Brake(); Console.WriteLine("--------------------"); bicycle.Ride(); bicycle.Wheelie(); bicycle.Brake(); Console.ReadLine(); }
static void Main(string[] args) { Sedan s = new Sedan(60); // Call SpeedUp() here Console.WriteLine(s.Describe()); Truck t = new Truck(45, 500); // Call SpeedUp() here Console.WriteLine(t.Describe()); Bicycle b = new Bicycle(10); // Call SpeedUp() here Console.WriteLine(b.Describe()); }
private void btnMakeMeansOfTransportation_Click(object sender, RoutedEventArgs e) { Bicycle bicycle1 = new Bicycle { HasEngine = true, HasFenders = true, Brand = "Granville" }; Bicycle bicycle2 = new Bicycle { HasEngine = false, HasFenders = false, Brand = "Merckx" }; Car car1 = new Car { NumberOfDoors = 2, HasEngine = true, Brand = "BMW" }; Car car2 = new Car { NumberOfDoors = 4, HasEngine = true, Brand = "Peugeot" }; Car car3 = new Car { NumberOfDoors = 3, HasEngine = false, Brand = "Trabant" }; List <Vehicle> vehicles = new List <Vehicle>(); vehicles.Add(bicycle1); vehicles.Add(bicycle2); vehicles.Add(car1); vehicles.Add(car2); vehicles.Add(car3); lblDetails.Content = ""; foreach (Vehicle vehicle in vehicles) { lblDetails.Content += $"{vehicle.ShowDetails()}\n"; } //foreach (Vehicle vehicle in vehicles) //{ // if (vehicle is Bicycle) // { // Bicycle bicycle = (Bicycle)vehicle; // bicycle.ShowDetails(); // } // if (vehicle is Car) // { // Car car = (Car)vehicle; // car.ShowDetails(); // } //} }
public void UpdateBicycleTest() { BicycleShop bicycleShop = new BicycleShop(); bicycle = new Bicycle("Racer", 3, 7, 999.99); bicycleShop.AddBicycle(bicycle); string name = "Yote"; int size = 4; int gears = 3; double prize = 199999; int id = 0; bicycleShop.UpdateBicycle(name, size, gears, prize, id); Assert.That(bicycleShop.GetBicycle(id).name == "Yote"); }
public async Task <ActionResult <Bicycle> > PutBicycle(int id, [FromBody] Bicycle bicycle) { if (bicycle == null) { return(BadRequest()); } if (id != bicycle.id) { return(NotFound()); } db.Update(bicycle); await db.SaveChangesAsync(); return(Ok(bicycle)); }
static void Main(string[] args) { Car BMWX5 = new Car(); //we can set the inherited properties just like normal ones BMWX5.Accelerate = 10; BMWX5.Decelerate = 12; BMWX5.Speed = 200; //and execute normal methods, just like inherited ones BMWX5.HonkHorn(); Bicycle Gepida = new Bicycle(); Gepida.RingBell(); Console.ReadKey(); }
public void BicycleObject() { string text = Intent.GetStringExtra("user") ?? "Data not available"; var user = JsonConvert.DeserializeObject <List <User> >(text); RestClient client = new RestClient("http://marichely.me:8099/"); RestRequest request = new RestRequest("bicycle/{id}", Method.GET); request.RequestFormat = DataFormat.Json; request.AddHeader("userapikey", user[0].ApiKey); request.AddParameter("id", bicId, ParameterType.UrlSegment); IRestResponse odgovor = client.Execute(request); if ((int)odgovor.StatusCode == 200) { bicObj = JsonConvert.DeserializeObject <Bicycle>(odgovor.Content); } }
private void buttonAdd_Click(object sender, EventArgs e) { Bicycle cycle = new Bicycle(); if (comboBoxModelType.Text == "Mountain_Bikes") { cycle.Serial = Convert.ToInt32(textBoxSerialNo.Text); cycle.Madeby = textBoxMadeBy.Text; cycle.Price = Convert.ToDouble(textBoxPrice.Text); cycle.Speed = Convert.ToInt32(textBoxSpeed.Text); cycle.Color = (EnumColor)comboBoxColor.SelectedIndex; Date dt = new Date(); dt.Day = Convert.ToInt32(this.textBoxDay.Text); dt.Month = Convert.ToInt32(this.textBoxMonth.Text); dt.Year = Convert.ToInt32(this.textBoxYear.Text); cycle.MadeDate = dt; cycle.RimType = (EnumRimType)comboBoxRimType.SelectedIndex; cycle.SuspType = (EnumSusType)comboBoxSusType.SelectedIndex; cycle.Model = (EnumModelType)comboBoxModelType.SelectedIndex; cycle.GroundClearance = Convert.ToDouble(textBoxGroundCl.Text); this.myBicycleList.Add(cycle); this.mountainBicycleList.Add(cycle); } if (comboBoxModelType.Text == "Road_Bikes") { cycle.Serial = Convert.ToInt32(textBoxSerialNo.Text); cycle.Madeby = textBoxMadeBy.Text; cycle.Price = Convert.ToDouble(textBoxPrice.Text); cycle.Speed = Convert.ToInt32(textBoxSpeed.Text); cycle.Color = (EnumColor)comboBoxColor.SelectedIndex; Date dt = new Date(); dt.Day = Convert.ToInt32(this.textBoxDay.Text); dt.Month = Convert.ToInt32(this.textBoxMonth.Text); dt.Year = Convert.ToInt32(this.textBoxYear.Text); cycle.MadeDate = dt; cycle.RimType = (EnumRimType)comboBoxRimType.SelectedIndex; cycle.Model = (EnumModelType)comboBoxModelType.SelectedIndex; cycle.SeatHeight = Convert.ToDouble(textBoxSeatHeight.Text); cycle.GroundClearance = Convert.ToDouble(textBoxGroundCl.Text); this.myBicycleList.Add(cycle); this.roadBicycleList.Add(cycle); } this.buttonAdd.Enabled = false; }
public TaskPage15() { Car car = new Car("Обычный автомобиль", 120, 4, "Бензин", 90); CarWithElectronic carWithElectronic = new CarWithElectronic("Авто напичканное электроникой", 150, 2, "Дизель", 70); Bicycle bicycle = new Bicycle("Велосипед", 40, 2); transports = new List <Transport>() { car, carWithElectronic, bicycle }; ConsoleTool.WriteLineConsoleGreenMessage("Опробуем поверхностное клонирование объекта с использованием небезизвестного интерфейса."); var clonedBicycle = (Bicycle)bicycle.Clone(); transports.Add(clonedBicycle); ConsoleTool.WriteLineConsoleGreenMessage("Выведем текущую инфомрацию по оригинальному и клонированному объектам. Она должна быть одинаковой: "); Console.WriteLine(bicycle.ToString()); Console.WriteLine(clonedBicycle.ToString()); ConsoleTool.WriteLineConsoleGreenMessage("А теперь изменим все три свойства для оригинального объекта. Эти изменения не должны затронуть клонированный. Затем повторим вывод: "); bicycle.Name = "Переименованный велосипед"; bicycle.MaxSpeed = 10; bicycle.PassengerCapacity = 1; Console.WriteLine(bicycle.ToString()); Console.WriteLine(clonedBicycle.ToString()); ConsoleTool.WriteLineConsoleGreenMessage("Рассмотрим пример использования глубокого клонирования. Он используется, когда класс имеет в своей структер поле с сылочным типом данных. Добавим нового водителя к нашему велосипеду."); bicycle.TransportDriver = new Driver("Алексей"); ConsoleTool.WriteLineConsoleGreenMessage("Клонируем наш велосипед еще раз."); var moreClonedBicycle = (Bicycle)bicycle.Clone(); transports.Add(moreClonedBicycle); Console.WriteLine(moreClonedBicycle.ToString()); ConsoleTool.WriteLineConsoleGreenMessage("Теперь переименуем водителя первого велосипеда и выведем все три имеющиеся у нас велосипеды новым способом: "); bicycle.TransportDriver.Name = "Александр"; foreach (Transport transport in transports) { if (transport is Bicycle) { Console.WriteLine(transport.ToString()); } } }
public ActionResult CreateBike(string year, DropdownDetails ddd) { var id = Session["ID"]; Bicycle b = new Bicycle { BrandId = ddd.SelectedBrand.Id, FrameSizeId = ddd.SelectedFrame.Id, TypeId = ddd.SelectedType.Id, UserId = Convert.ToInt32(id), WheelSizeId = ddd.SelectedWheel.Id, Year = year }; client.CreateBicycle(b); return(RedirectToAction("ViewBikes", "Bike")); }
public Bicycle GetBikeByYear(string year) { try { using (var db = new Context()) { Bicycle b = db.Bikes .Where(i => i.Year == year) .OrderByDescending(i => i.ID) .FirstOrDefault(); return(b); } } catch (Exception) { throw; } }
public void AddBicycle(Bicycle bicycle) { //Create an object postedObj with Bicycle table attributes var postedObj = new Bicycle { Price = bicycle.Price, ProductionYear = bicycle.ProductionYear, ProductModel = bicycle.ProductModel, Gender = bicycle.Gender, BrandId = bicycle.BrandId, CategoryId = bicycle.CategoryId }; // Add to the list _bicyleStoreContext.Bicycles.Add(postedObj); // Save the list _bicyleStoreContext.SaveChanges(); }
public IHttpActionResult CreateBicycle(Bicycle bicycle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _repo.Add(bicycle); } catch (Exception ex) { throw; } return(CreatedAtRoute("DisplayRoute", new { id = bicycle.Id }, bicycle)); }
static void Main(string[] args) { // create an instance of Bicycle and upcast it to object object myObject = new Bicycle("Adam Freeman", 24, "Comfort"); // use the is keyword to check the type bool isCar = myObject is Car; bool isBike = myObject is Bicycle; bool isObject = myObject is object; Console.WriteLine("Is Car? {0}", isCar); Console.WriteLine("Is Bike? {0}", isBike); Console.WriteLine("Is Object? {0}", isObject); // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
IEnumerator BicycleTime(Create create, Bicycle bicycle) { float timer = 10; GameMaster.SPEEDOFROAD += GameMaster.BONUSSPEEDOFROAD; while (timer >= 0) { yield return(new WaitForFixedUpdate()); timer -= Time.deltaTime; timerText.text = ((int)timer).ToString(); } GameMaster.SPEEDOFROAD -= GameMaster.BONUSSPEEDOFROAD; timerText.text = "0"; create.DoAllFalse(); bicycle.currentParts = 0; bicycle.RestartCurrent(); animation.SetBool("Bicycle", false); }
public ActionResult <List <Bicycle> > GetBicycleByBrandId(int brandId) { var query = _bicyleStoreContext.Bicycles.Where(u => u.BrandId == brandId) .Select(c => new { c.ProductModel, c.ProductionYear }).ToList(); //adds the bicycles found in the lists to the bicycleList initialized in the beginning of this class foreach (var q in query) { Bicycle bbr = new Bicycle(); bbr.ProductModel = q.ProductModel; bbr.ProductionYear = q.ProductionYear; bicycleList.Add(bbr); } return(bicycleList); }
public ActionResult Create([Bind("Id,Type,Size,Gender,Brand,LocationId")] Bicycle bicycle) { TempData["Message"] = string.Empty; using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri($"{baseurl}Bicycles"); //HTTP POST var postTask = httpClient.PostAsJsonAsync <Bicycle>("Bicycles", bicycle); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { TempData["Message"] = "Bicycle has been created."; return(RedirectToAction("Index")); } } TempData["Message"] = "Employee has not been created."; return(View(bicycle)); }
public static void Classes() { // 使用new初始化对象 Bicycle trek = new Bicycle(); // 调用对象的方法 trek.SpeedUp(3); // 你应该一直使用setter和getter方法 trek.Cadence = 100; // 查看对象的信息. Console.WriteLine("trek info: " + trek.Info()); // 实例化一个新的Penny Farthing PennyFarthing funbike = new PennyFarthing(1, 10); Console.WriteLine("funbike info: " + funbike.Info()); Console.Read(); }
public async Task <IActionResult> Post([FromBody] CreateBicycle createBicycle) { var bicycle = new Bicycle { UserId = createBicycle.UserId, ProductionDate = createBicycle.ProductionDate, Type = createBicycle.Type }; await _context.AddAsync(bicycle); await _context.SaveChangesAsync(); return(Created(bicycle.BicycleId.ToString(), new BicycleViewModel { UserId = bicycle.UserId, ProductionDate = bicycle.ProductionDate, Type = bicycle.Type })); }
static void Main(string[] args) { // create an instance of Bicycle and upcast it to object object myObject = new Bicycle("Adam Freeman", 24, "Comfort"); // use the as operator to convert the type Bicycle myBike = myObject as Bicycle; // try to convert the object to a Car Car myCar = myObject as Car; // print out the result of the as operations Console.WriteLine("myBike is null? {0}", myBike == null); Console.WriteLine("myCar is null? {0}", myCar == null); // wait for input before exiting Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
static BicycleSeed() { const int bicycleCount = 5; DataToSeed = new Collection <Bicycle>(); for (int i = 0; i < bicycleCount; i++) { var bicycle = new Bicycle { Id = Guid.NewGuid(), Name = $"Bicycle abc{i + 1}", RentalStatus = RandomHelpers.GetRentalStatus(), Price = 11999 + (i * 500), TypeBicycleId = TypeBicycleSeed.DataToSeed.GetRandomElement().Id }; DataToSeed.Add(bicycle); } }
public IEnumerable <Bicycle> BuildBicycleList(IEnumerable <DAO.User> userList) { var bicycleList = new List <Bicycle>(); foreach (var user in userList) { for (int i = 0; i < (user.UserId % 2 == 0 ? 2 : 1); i++) { var bicycle = new Bicycle() { BicycleId = bicycleList.Count + 1, UserId = user.UserId, ProductionDate = DateTime.Now.AddYears(-user.UserId - i), Type = ((BicycleType)(new Random().Next(14))).ToString() }; bicycleList.Add(bicycle); } } return(bicycleList); }
static void Main(string[] args) { IEnginedVehicle car = new Car(); Console.WriteLine("Car:"); car.Move(); car.StartEngine(); car.Move(); car.StopEngine(); IVehicle bicycle = new Bicycle(); Console.WriteLine("Bicycle:"); bicycle.Move(); Console.ReadLine(); }
public void DeleteBicycleTest() { BicycleShop bicycleShop = new BicycleShop(); bicycle = new Bicycle("Racer", 3, 7, 999.99); bicycleShop.AddBicycle(bicycle); bicycle = new Bicycle("Shuut", 5, 9, 1.99); int id = 0; bicycleShop.AddBicycle(bicycle); Console.WriteLine(bicycleShop.GetBicycle(id).name); Console.WriteLine(bicycleShop.GetBicycle(id + 1).name); bicycleShop.DeleteBicycle(id); Console.WriteLine(bicycleShop.GetBicycle(id).name); Assert.That(bicycleShop.GetBicycle(id).name == "Shuut"); }
static void Main(string[] args) { //creating new instance of the Car class Car myCar = new Car(); Console.WriteLine(myCar.Make); Console.ReadLine(); //Overloaded constructer demo Car myThirdCar = new Car("Nissan", "Altima", 1999, "Grey"); Console.WriteLine(myThirdCar.Model); Console.ReadLine(); //static method demo Car.myMethod(); //Static class Bicycle with a static method Bicycle.myBikeMessage(); }
public void Delete_Removes_Bicycle() { var bicycleID = 1; var deletedBicycle = new Bicycle(1, "name", "image", "description", "style", 1); var bicycleList = new List <Bicycle>() { deletedBicycle, new Bicycle(2, "2name", "2image", "2description", "2style", 2) }; bicycleRepo.GetByID(bicycleID).Returns(deletedBicycle); bicycleRepo.When(d => d.Delete(deletedBicycle)) .Do(d => bicycleList.Remove(deletedBicycle)); bicycleRepo.GetAll().Returns(bicycleList); var result = underTest.Delete(bicycleID); Assert.DoesNotContain(deletedBicycle, result); //Assert.All(result, item => Assert.Contains("second item", item.Name)); }
public void HandleClient(object obj) { TcpClient client = (TcpClient)obj; StreamWriter sWriter = new StreamWriter(client.GetStream(), Encoding.ASCII); StreamReader sReader = new StreamReader(client.GetStream(), Encoding.ASCII); Boolean bClientConnected = true; String sData = null; while (bClientConnected) { sData = sReader.ReadLine(); Protocol bicycleTest = new Bicycle(sData) as Protocol; var res = bicycleTest.BuildAnswer(); Console.WriteLine("Client > " + sData); sWriter.WriteLine(res); sWriter.Flush(); } }
public IHttpActionResult UpdateBicycle(int id, Bicycle bicycle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bicycle.Id) { return(BadRequest()); } try { _repo.Save(bicycle); } catch (Exception ex) { throw new Exception("Can't save changes!"); } return(StatusCode(HttpStatusCode.NoContent)); }
public Main() { InitializeComponent(); List <Vehicle> vehicles = new List <Vehicle>(); List <Driver> drivers = new List <Driver>(); Driver bob = new Driver(123456789, "Bob"); Driver steve = new Driver(987654321, "Steve"); Driver arnold = new Driver(111111111, "Arnold"); SportCar mazdaCar = new SportCar(1548967, "Mazda", "Red"); Truck fordTruck = new Truck(5686623, "Ford", "White"); Bicycle bmx = new Bicycle(1775483, "BMX", "Blue"); mazdaCar.FirstDriver = bob; bmx.FirstDriver = arnold; AccessList.drivers.Add(steve); AccessList.drivers.Add(arnold); AccessList.drivers.Add(bob); AccessList.vehicles.Add(mazdaCar); AccessList.vehicles.Add(fordTruck); AccessList.vehicles.Add(bmx); }
public async Task <int> AddVehicle <T>(T input) where T : AddBycicleViewModel { var bicycle = new Bicycle() { Type = input.Type, Made = input.Made, Speeds = input.Speeds, Size = input.Size, SizeOfTires = input.SizeOfTires, IsAvailable = true, PriceForHour = input.PriceForHour, Description = input.Description, }; await this.db.Bicycles.AddAsync(bicycle); await this.db.SaveChangesAsync(); return(bicycle.Id); }
protected void submitButton_Click(object sender, EventArgs e) { var currentUser = System.Web.Security.Membership.GetUser(); var bicycleID = Request.QueryString["bicycleID"]; Bicycle b; if (bicycleID == null) { // New bicycle b = new Bicycle(); b.Id = Guid.NewGuid(); b.Owner = currentUser; this.db.Bicycles.InsertOnSubmit(b); } else { // Existing bicycle b = (from bi in this.db.Bicycles where bi.UserId == (Guid)currentUser.ProviderUserKey && bi.Id == Guid.Parse(bicycleID) select bi).FirstOrDefault(); if (b == null) return; } b.Size = int.Parse(sizeTextBox.Text); b.Type = typeTextBox.Text; b.Fault = faultTextBox.Text; this.db.SubmitChanges(); Response.Redirect("ListBicycles"); }