/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
static void TestCar()
{
Car Car1 = new Car();
Car1.On();
Car1.Drive(80);
Car1.Speed(10);
//Car1.Stop();
Car1.Slow(30);
Car1.Slow(60);
Car1.Off();
}
static void TestBus()
{
Bus Bus1 = new Bus();
Bus1.Id = 19;
Bus1.c = 50;
Bus1.Company = "Egged";
Bus1.Print();
bool b = Bus1.IsEmpty();
Console.WriteLine(b);
Bus1.SetP(11);
b = Bus1.IsEmpty();
Console.WriteLine(b);
Bus1.Print();
Bus Bus2 = new Bus();
Bus2.Id = 101;
Bus2.c = 15;
Bus2.Company = "Dan";
Bus2.Print();
Bus2.SetP(7);
Bus2.Print();
}
static void Main() {
Console.WriteLine("Hello World");
TestBus();
TestCar();
}
}
using System;
public class Car
{
//الصفات
//رقم السيارة
public int Id;
//سرعة السيارة
public int speed;
//تعمل -المحرك يعمل
public bool isOn;
//اسم الشركة
public string company;
//اللون
public string color;
// البناء
// العمليات
public void Drive(int d)
{
this.speed = d;
Console.WriteLine("Drive - Speed:{0}", this.speed);
}
public void Speed(int d)
{
this.speed += d;
Console.WriteLine("Speed - Speed:{0}", this.speed);
}
public void Slow(int d)
{
this.speed -= d;
Console.WriteLine("Slow - Speed:{0}", this.speed);
}
public void Off()
{
if (this.speed == 0)
{
this.isOn= false;
}
else
this.isOn = true;
}
public void On()
{
if (this.speed != 0)
{
this.isOn = false;
}
else
this.isOn = true;
}
}
using System;
public class Bus
{
//الصفات
//رقم الخط
public int Id;
//السعة
public int c;
//عدد الركاب
public int p;
//اسم الشركة
public string Company;
// البناء
// العمليات
public void SetP(int p)
{
if (p <= this.c)
{
this.p = p;
Console.WriteLine("P:{0}", this.p);
}
else
Console.WriteLine("Error - P:{0}", p);
}
public bool IsEmpty()
{
if (this.p == 0)
{
return true;
}
else
return false;
}
public bool IsFull()
{
if (this.p == this.c)
{
return true;
}
else
return false;
}
public void Inc(int p)
{
int max = this.c - this.p;
if (p <= max)
{
this.p += p;
Console.WriteLine("P:{0}", this.p);
}
else
Console.WriteLine("Error - P:{0}", p);
}
public void Dec(int p)
{
int max = this.c - this.p;
if (p <= this.p)
{
this.p -= p;
Console.WriteLine("P:{0}", this.p);
}
else
Console.WriteLine("Error - P:{0}", p);
}
public void Print()
{
Console.WriteLine("Id: {0}, C:{1}, P:{2}, Company:{3}",
this.Id,
this.c,
this.p,
this.Company
);
}
}