BasicKnowledgeCSharp/LessonsAndTasks/Lesson 56 - Методы и классы, ООП, вызов метода объекта класса/Car.cs
Dvurechensky 058c8f2679 1.0
Main
2024-10-05 09:59:53 +03:00

34 lines
709 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
class Car
{
private int speed = 0;
/// <summary>
/// Пример инкапсуляции поля speed
/// </summary>
public void PrintSpeed()
{
if (speed == 0)
Console.WriteLine("Стоим на месте");
if (speed > 0)
Console.WriteLine($"Едем вперед со скоростью {speed} км\\ч");
if (speed < 0)
Console.WriteLine($"Едем назад со скоростью {-speed} км\\ч");
}
public void DriveForward()
{
speed = 60;
}
public void Stop()
{
speed = 0;
}
public void DriveBackward()
{
speed = -60;
}
}