Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace DefiningClasses
- {
- public class Car
- {
- public string model;
- public double fuelAmount;
- public double fuelConsumptionPerKilometer;
- public double travelledDistance = 0;
- //{model} {fuelAmount} {fuelConsumptionFor1km};
- public Car(string model, double fuelAmoount, double fuelConsumptionFor1km)
- {
- this.model = model;
- this.fuelAmount = fuelAmoount;
- this.fuelConsumptionPerKilometer = fuelConsumptionFor1km;
- this.travelledDistance = 0;
- }
- //;Drive {carModel} {amountOfKm};
- public void Drive(double amountOfKm)
- {
- var consumption = amountOfKm * this.fuelConsumptionPerKilometer;
- if (this.fuelAmount - consumption < 0)
- {
- Console.WriteLine("Insufficient fuel for the drive");
- }
- else
- {
- this.fuelAmount -= (consumption) ;
- this.travelledDistance += amountOfKm;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment