Advertisement
BSO90

Car.Cs

Oct 8th, 2021
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5.  
  6. namespace CarManufacturer
  7. {
  8.    public class Car
  9.     {
  10.         public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption, Engine engine, Tire[] tires)
  11.         {
  12.             this.Make = make;
  13.             this.Model = model;
  14.             this.Year = year;
  15.             this.FuelQuantity = fuelQuantity;
  16.             this.FuelConsumption = fuelConsumption;
  17.             this.Engine = engine;
  18.             this.Tire = tires;
  19.         }
  20.  
  21.        
  22.        
  23.         public string Model { get; set; }
  24.  
  25.         public string Make { get; set; }
  26.  
  27.         public int Year { get; set; }
  28.  
  29.         public double FuelQuantity { get; set; }
  30.  
  31.         public double FuelConsumption { get; set; }
  32.  
  33.         public Engine Engine { get; set; }
  34.         public Tire[] Tire { get; set; }
  35.  
  36.         public void Drive(double distance)
  37.         {
  38.             double consumption = 20 * this.FuelConsumption / 100;
  39.             if (this.FuelQuantity - consumption <= 0)
  40.             {
  41.                 Console.WriteLine("Not enough fuel to perform this trip!");
  42.             }
  43.             else
  44.             {
  45.                 this.FuelQuantity -= consumption;
  46.             }
  47.         }
  48.         public string WhoAmI()
  49.         {
  50.             return $"Make: {this.Make}\nModel: {this.Model}\nYear: {this.Year}\nHorsePowers: {this.Engine.HorsePower}\nFuelQuantity: {this.FuelQuantity}";
  51.         }
  52.     }
  53. }
  54.        
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement