Zwracam honor
Klasa pojazd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Pojazd : IPojazd
{
private string _marka;
private int _ileKol;
private string _model;
private int _cena;
public string Marka
{
get
{
return _marka;
}
set
{
_marka = value;
}
}
public int IleKol
{
get
{
return _ileKol;
}
set
{
_ileKol = value;
}
}
public string Model
{
get
{
return _model;
}
set
{
_model = value;
}
}
public int Cena
{
get
{
return _cena;
}
set
{
_cena = value;
}
}
public Pojazd(string marka, string model)
{
Marka = marka;
Model = model;
}
public Pojazd(string marka, string model, int ilekol, int cena)
{
Marka = marka;
Model = model;
IleKol = ilekol;
Cena = cena;
}
public Pojazd() { }
public virtual void Jedz()
{
System.Console.WriteLine("jedzie z klasy pojazd");
}
}
}
Klasa Rower
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Rower : Pojazd
{
private string _typLancucha;
public string TypLancucha
{
get
{
return _typLancucha;
}
set
{
_typLancucha = value;
}
}
public Rower(string marka, string model, int ileKol, int cena, string typLancucha)
:base(marka, model, ileKol, cena)
{
TypLancucha = typLancucha;
}
public override void Jedz()
{
//base.Jedz();
Console.WriteLine("z klasy rower");
}
}
}
Klasa Car
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Car : Pojazd
{
private string _jakiePaliwo;
public string JakiePaliwo
{
get
{
return _jakiePaliwo;
}
set
{
_jakiePaliwo = value;
}
}
public Car(string marka, string model, int ileKol, int cena, string jakiePaliwo)
:base(marka, model, ileKol, cena)
{
JakiePaliwo = jakiePaliwo;
}
public override void Jedz()
{
//base.Jedz();
Console.WriteLine("to napisane z klasy CAR");
}
}
}
Interfejs IPojazd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
interface IPojazd
{
string Marka { get; set; }
string Model { get; set; }
int IleKol { get; set; }
int Cena { get; set; }
void Jedz();
}
}
Klasa Main
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
IPojazd x = new Pojazd("audi", "model");
System.Console.WriteLine("Marka: {0}, Model: {1}", x.Marka, x.Model);
IPojazd y = new Car("audi", "a4", 4, 2200, "diesel");
System.Console.WriteLine(y.Marka + y.Model + y.IleKol + y.Cena);
IPojazd z = new Rower("romet", "c40", 2, 200, "prosty");
System.Console.WriteLine(z.Marka + z.Model + z.IleKol + z.Cena);
//System.Console.WriteLine(z.TypLancucha); // <------------------------- chcę aby ta linijka kodu mogła się wykonać
System.Console.ReadLine();
}
}
}