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.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace OOP_first_class
- {
- internal class Car
- {
- //fields
- public string brand;
- public string model;
- public string color;
- private int maximumSpeed;
- private int horsePower;
- private int engineCapacity;
- private double oilTemperature;
- public double OilTemperatureC
- {
- get { return oilTemperature; }
- set {
- if (value > 0 && value < 150)
- oilTemperature = value;
- else
- oilTemperature = 90;
- }
- }
- public double OilTemperatureK
- {
- get { return oilTemperature + 273.2; }
- set
- {
- if (value > 273.2 && value < 423.2)
- oilTemperature = value - 273.2;
- else
- oilTemperature = 90;
- }
- }
- public int EngineCapcity
- {
- get { return engineCapacity; }
- set { engineCapacity = value; }
- }
- //properties
- public int MaximumSpeed
- {
- get { return maximumSpeed; }
- set
- {
- if (value > 0 && value < 350)
- maximumSpeed = value;
- else
- maximumSpeed = 190;
- }
- }
- public int HorsePower
- {
- get { return horsePower; }
- set
- {
- if (value > 0 && value < 1000)
- horsePower = value;
- else
- horsePower = 100;
- }
- }
- public void SetMaximumSpeed(int speed)
- {
- if (speed > 0 && speed < 350)
- maximumSpeed = speed;
- else
- maximumSpeed = 190;
- }
- public int GetMaximumSpeed()
- {
- return maximumSpeed;
- }
- //constructors
- public Car()
- {
- brand = "Fiat";
- model = "Uno";
- color = "Grey";
- maximumSpeed = 80;
- }
- public Car(string _brand, string _model, string _color = "Yellow", int _maximumSpeed = 350)
- {
- brand = _brand;
- model = _model;
- color = _color;
- maximumSpeed = _maximumSpeed;
- }
- public Car(Car _car)
- {
- brand = _car.brand;
- model = _car.model;
- color = _car.color;
- maximumSpeed = _car.maximumSpeed;
- }
- //methods
- public void PrintCarInfo()
- {
- Console.WriteLine($"Our car is: {brand} {model}, " +
- $"color: {color}, maximum speed is {maximumSpeed}km/h");
- }
- public void GoForward()
- {
- Console.WriteLine("Car is going forward");
- }
- public void GoBackward()
- {
- Console.WriteLine("Car is going backward");
- }
- public void TurnLeft()
- {
- Console.WriteLine("Car is turning left");
- }
- public void TurnRight()
- {
- Console.WriteLine("Car is turning right");
- }
- public double CalculateTheTime(int distance)
- {
- return (double)distance / maximumSpeed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement