1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
namespace A025
{
class Program
{ static void Main(string[] args)
{ Tier tier1 = new Tier("Löwe", 300);
Tier tier2 = new Tier("Puma", 250);
Tier tier3 = new Pferde("Esel", 150, true);
Tier tier4 = new Voegel("Kolibri", 1, true);
Zoo zoo = new Zoo();
zoo.hinzu(tier1);
zoo.hinzu(tier2);
zoo.hinzu(tier3);
zoo.hinzu(tier4);
Console.WriteLine(zoo);
zoo.hinweg(tier4);
Console.WriteLine(zoo);
} }
class Zoo
{
ArrayList a = new ArrayList();
public ArrayList hinzu(Tier tier)
{ this.a.Add(tier);
return a; }
public ArrayList hinweg(Tier tier)
{ this.a.Remove(tier);
return a; }
public override string ToString()
{
foreach (Tier t in a)
{
Console.WriteLine(t.Name + " heißt es bei Gewicht " + t.Gewicht);
}
return "";
}
}
class Pferde : Tier
{
bool zuchtfaehig;
public Pferde(string name, int gewicht, bool zuchtfaehig) : base(name, gewicht)
{
this.zuchtfaehig = zuchtfaehig;
}
}
class Voegel : Tier
{
bool flugfaehig;
public Voegel(string name, int gewicht, bool flugfaehig) : base(name, gewicht)
{ this.flugfaehig = flugfaehig; } }
class Tier
{
string name;
int gewicht;
public Tier(string name, int gewicht)
{ this.name = name;
this.gewicht = gewicht; }
// property
public string Name
{ get { return this.name; }
set { this.name = value; } }
// property public int Gewicht
{ get { return this.gewicht; }
set { this.gewicht = value; }
}
}
}
|