using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace test {
class test { public static void showMod(Model obj) { Console.WriteLine("Model: " + obj.model); } public static void showCap(Model obj) { Console.WriteLine("Capacity: " + obj.capacity); } public static void showAcc(Model obj) { Console.WriteLine("Accelerate: " + obj.accelerate); } public static void showCol(Model obj) { Console.WriteLine("Color: " + obj.color); }
public static void Main(string[] args) { Model[] tab = new Model[7]; Model.ShowCallBack[] shows = new Model.ShowCallBack[4]; shows[0] = new Model.ShowCallBack(test.showMod); shows[1] = new Model.ShowCallBack(test.showCap); shows[2] = new Model.ShowCallBack(test.showAcc); shows[3] = new Model.ShowCallBack(test.showCol); tab[0] = new Osobowy( 10, "BMW 316", 0, "osobowy", 4, 4, "czerwony"); tab[1] = new Osobowy(8, "BMW 520", 0, "osobowy", 4, 4, "zielony"); tab[2] = new Osobowy(5, "BMW 740", 0, "osobowy", 4, 4, "srebrny"); tab[3] = new Osobowy(9, "BMW X3-1", 0, "osobowy", 4, 4, "zielony"); tab[4] = new Osobowy(8, "BMW X5-2", 0, "osobowy", 4, 4, "czerwony"); tab[5] = new Dostawczy( 14, "Fiat Doblo", 700, "dostawczy", 4, 4, "biały"); tab[6] = new Dostawczy( 12, "Ford Tranzit", 750, "dostawczy", 4, 4, "szary"); Random r = new Random(); int which; Console.WriteLine("Model \t{0,8} \t{1,11} \t{2,5}", "Kolor", "Ładowność", "Przyśpieszenie"); for (int i = 0; i < 7; i++) { // cw1/2 //Console.WriteLine(tab[i].model + "/t{0,8} \t{1,11} \t{2,5}", tab[i].color , tab[i].capacity, tab[i].accelerate); which = r.Next(0,4); tab[i].show(shows[which]); } Console.ReadKey(); }
}
public class Samochód { public string type; public int doors; public int wheels; public string color;
public Samochód(string typ, int door, int wheel, string col) { type = typ; doors = door; wheels = wheel; color = col; } /* cw2 public virtual void show() { Console.WriteLine("Nie przeciazyles"); } */ }
public class Model : Samochód { public int accelerate; public string model; public int capacity;
public Model(int acc, string mod, int cap, string typ, int door, int wheel, string col) : base( typ, door, wheel, col) { accelerate = acc; model = mod; capacity = cap;
}
public delegate void ShowCallBack(Model test);
public void show(ShowCallBack test) { test(this); } }
/* interface Ishow { public void show(); } */
public class Osobowy : Model //, Ishow cw2 { public Osobowy(int acc, string mod, int cap, string typ, int door, int wheel, string col) : base(acc, mod, cap, typ, door, wheel, col) { }
/* cw2 public override void show() { Console.WriteLine(model + "/t{0,8} \t{1,11} \t{2,5}",color, "x", accelerate); } */ }
public class Dostawczy : Model //, Ishow cw2 { public Dostawczy(int acc, string mod, int cap, string typ, int door, int wheel, string col) : base(acc, mod, cap, typ, door, wheel, col) { } /* cw 2 public override void show() { Console.WriteLine(model + "/t{0,8} \t{1,11} \t{2,5}", color, capacity, accelerate); } */ } }
|