/******************************************************************************
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 Car{ //Asosiy class
public string name;
public string brend;
public string color;
protected double yoqilgi=20; //mero classda mashinani harakatlantirish uchun istalgan qiymat kiritish mumkin
private uint narx;
bool bor;
// xossalar
public string writeread //yozib o'qish
{
get { return name; }
set { name = value; }
}
public uint read //faqat o'qish
{
get { return narx; }
}
public string write //faqat yozish
{
set { brend = value; }
}
protected double avto //avtomatik
{
get;
set;
}
// xossalar asosida Konstruktor
public Car(string Nom, string Brend, uint Narx, string Color, bool Bormi)
{
writeread = Nom;
brend = Brend;
narx = Narx;
color = Color;
bor = Bormi;
}
// xossa uchun metod
public void Info()
{
Console.WriteLine("--------------------------------");
Console.WriteLine(" '"+name+"' mashinasi haqida ma'lumot");
Console.WriteLine("Ishlab chiqaruvchi: " + brend);
Console.WriteLine("Uning rangi : " + color);
Console.WriteLine("Uning bakida : " + yoqilgi + " litr benzin bor");
Console.WriteLine("Uning narxi: " + narx + " $");
if (bor) Console.WriteLine("Sotuvda BOR!!!");
else Console.WriteLine("Sotuvda YO'Q!");
Console.WriteLine("--------------------------------");
}
// maydonlar asosida Konstruktor
public Car(string model, string modelBrend, string modelColor)
{
name=model;
brend=modelBrend;
color=modelColor;
}
}
class superCar : Car{ // meros class
private int narxi = 5000000;
public int yil;
private double rasxod = 0.1;
public double tezlik;
// Metodlar
// Mashina harakatlanganda yoqilg'ini hisoblash uchun
public void yur(double y){
Console.WriteLine("Sizda "+yoqilgi+" litr yoqilgi bor edi");
yoqilgi = yoqilgi - y * rasxod;
Console.WriteLine("Sizda "+yoqilgi+" litr yoqilgi qoldi");
}
// Mashina yoqilg'i quyganda yoqilg'ini hisoblash uchun
public void zapravka(double z){
yoqilgi+=z;
Console.WriteLine("Yoqilg'ingiz "+yoqilgi+" litr bo'ldi");
}
// Mashina sotib olish uchun
public void buy(){
Console.WriteLine("Ushbu mashinadan nechta sotib olishni xohlaysiz?");
Console.Write("Sonini kiriting = ");
int count = Convert.ToInt32(Console.ReadLine());
Console.Write("Qancha pulingiz bor? Kiriting($): ");
int money = Convert.ToInt32(Console.ReadLine());
if(count*money>narxi){
Console.WriteLine("Pulingiz yetadi xo'jayin. Sotib olishingiz mumkin :)");
}else{
Console.WriteLine("Afsuski pulingiz yetmaydi :(");
}
}
// Mashina narxini chiqarish uchun
public void ShowNarx(){
Console.WriteLine();
Console.WriteLine("----------Ushbu mashinaning narxi: "+narxi+"----------");
Console.WriteLine();
}
// Asosiy classga asoslanib yaratilgan Konstruktor
public superCar(string model, string modelBrend, string modelColor, double modelSpeed, int modelYear):base(model,modelBrend,modelColor)
{
name=model;
brend=modelBrend;
color=modelColor;
tezlik=modelSpeed;
yil=modelYear;
}
}
class Mahmudjonova {
public static string name;
public static string brend;
public static uint narx;
public static string color;
public static bool bor;
static void Main()
{
// ---------- P.S : Dasturdan qulay foydalanish uchun keraklisidan tashqarilarini izohga olib qo'yish tavsiya qilinadi
// Car avto = new Car("Gentra", "Ravon", "Qora");
// Console.WriteLine("Ushbu mashinaning nomi "+avto.name + " U " + avto.brend + " kompaniyasi tomonidan ishlab chiqarilgan. Uning ranggi " + avto.color);
Main2();
Car avtoXossa = new Car(name, brend, narx, color, bor);
avtoXossa.Info();
// superCar avto1 = new superCar("Aventador", "Lamborghini", "Sariq",300, 2020);
// Console.WriteLine("Ushbu mashinaning nomi "+avto1.name + " U " + avto1.brend + " kompaniyasi tomonidan ishlab chiqarilgan. Uning ranggi " + avto1.color +". Maksimal tezligi "+avto1.tezlik+"km/h. Va u "+ avto1.yil+"-yilda ishlab chiqarilgan.");
// avto1.ShowNarx();
// avto1.buy();
// avto1.yur(10);
// avto1.yur(100);
// avto1.zapravka(5);
}
public static void Main2()
{
Console.Write("Mashina nomini kiriting: ");
name = Console.ReadLine();
Console.Write("Mashina Brendini kiriting: ");
brend = Console.ReadLine();
Console.Write("Mashina narxini kiriting: ");
narx = uint.Parse(Console.ReadLine());
Console.Write("Mashina rangini kiriting: ");
color = Console.ReadLine();
Console.Write("Sotuvda bormi? ");
string Bor = Console.ReadLine();
bor = (Bor == "ha" ||Bor == "HA" ||Bor == "Ha" ||Bor == "hA");
}
}
Do'stlaringiz bilan baham: |