Advertisement
cuniszkiewicz

CarClass

Mar 17th, 2025
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace OOP_first_class
  9. {
  10.     internal class Car
  11.     {
  12.         //fields
  13.         public string brand;
  14.         public string model;
  15.         public string color;
  16.         private int maximumSpeed;
  17.         private int horsePower;
  18.         private int engineCapacity;
  19.        
  20.         private double oilTemperature;
  21.  
  22.         public double OilTemperatureC
  23.         {
  24.             get { return oilTemperature; }
  25.             set {
  26.                 if (value > 0 && value < 150)
  27.                     oilTemperature = value;
  28.                 else
  29.                     oilTemperature = 90;
  30.             }
  31.         }
  32.         public double OilTemperatureK
  33.         {
  34.             get { return oilTemperature + 273.2; }
  35.             set
  36.             {
  37.                 if (value > 273.2 && value < 423.2)
  38.                     oilTemperature = value - 273.2;
  39.                 else
  40.                     oilTemperature = 90;
  41.             }
  42.         }
  43.  
  44.  
  45.         public int EngineCapcity
  46.         {
  47.             get { return engineCapacity; }
  48.             set { engineCapacity = value; }
  49.         }
  50.  
  51.  
  52.         //properties
  53.         public int MaximumSpeed
  54.         {
  55.             get { return maximumSpeed; }
  56.  
  57.             set
  58.             {
  59.                 if (value > 0 && value < 350)
  60.                     maximumSpeed = value;
  61.                 else
  62.                     maximumSpeed = 190;
  63.             }
  64.         }
  65.         public int HorsePower
  66.         {
  67.             get { return horsePower; }
  68.             set
  69.             {
  70.                 if (value > 0 && value < 1000)
  71.                     horsePower = value;
  72.                 else
  73.                     horsePower = 100;
  74.  
  75.             }
  76.         }
  77.         public void SetMaximumSpeed(int speed)
  78.         {
  79.             if (speed > 0 && speed < 350)
  80.                 maximumSpeed = speed;
  81.             else
  82.                 maximumSpeed = 190;
  83.         }
  84.  
  85.         public int GetMaximumSpeed()
  86.         {
  87.             return maximumSpeed;
  88.         }  
  89.  
  90.  
  91.         //constructors
  92.  
  93.         public Car()
  94.         {
  95.             brand = "Fiat";
  96.             model = "Uno";
  97.             color = "Grey";
  98.             maximumSpeed = 80;
  99.         }
  100.  
  101.         public Car(string _brand, string _model, string _color = "Yellow", int _maximumSpeed = 350)
  102.         {
  103.             brand = _brand;
  104.             model = _model;
  105.             color = _color;
  106.             maximumSpeed = _maximumSpeed;
  107.         }
  108.  
  109.         public Car(Car _car)
  110.         {
  111.             brand = _car.brand;
  112.             model = _car.model;
  113.             color = _car.color;
  114.             maximumSpeed = _car.maximumSpeed;
  115.         }
  116.  
  117.         //methods
  118.         public void PrintCarInfo()
  119.         {
  120.             Console.WriteLine($"Our car is: {brand} {model}, " +
  121.             $"color: {color}, maximum speed is {maximumSpeed}km/h");
  122.         }
  123.  
  124.         public void GoForward()
  125.         {
  126.             Console.WriteLine("Car is going forward");
  127.  
  128.         }
  129.  
  130.         public void GoBackward()
  131.         {
  132.             Console.WriteLine("Car is going backward");
  133.  
  134.         }
  135.  
  136.         public void TurnLeft()
  137.         {
  138.             Console.WriteLine("Car is turning left");
  139.  
  140.         }
  141.         public void TurnRight()
  142.         {
  143.             Console.WriteLine("Car is turning right");
  144.  
  145.         }
  146.  
  147.         public double CalculateTheTime(int distance)
  148.         {
  149.  
  150.             return (double)distance / maximumSpeed;
  151.         }
  152.     }
  153. }
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement