Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DefiningClasses
- {
- public class Car
- {
- string model;
- double fuelAmount;
- double fuelConsumptionPerKilometer;
- double travelledDistance;
- public Car()
- {
- }
- public Car(string model, double fuelAmount, double fuelConsumption)
- {
- this.Model = model;
- this.FuelAmount = fuelAmount;
- this.FuelConsumptionPerKilometer = fuelConsumption;
- this.TravelledDistance = 0;
- }
- public string Model
- {
- get
- {
- return model;
- }
- set
- {
- this.model = value;
- }
- }
- public double FuelAmount
- {
- get
- {
- return fuelAmount;
- }
- set
- {
- this.fuelAmount = value;
- }
- }
- public double FuelConsumptionPerKilometer
- {
- get
- {
- return fuelConsumptionPerKilometer;
- }
- set
- {
- this.fuelConsumptionPerKilometer = value;
- }
- }
- public double TravelledDistance
- {
- get
- {
- return travelledDistance;
- }
- set
- {
- this.travelledDistance = value;
- }
- }
- public void CanIReachTheDistance(string model, double amountKm)
- {
- double neededLitres = amountKm * this.FuelConsumptionPerKilometer;
- if (this.FuelAmount >= neededLitres)
- {
- this.fuelAmount -= neededLitres;
- this.TravelledDistance += amountKm;
- }
- else
- {
- Console.WriteLine("Insufficient fuel for the drive");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement