Ejemplo n.º 1
0
    public static void Main()
    {
        /* einige Testdaten */
          /* some testdata */
          Baum    b1 = new Baum("Eiche", 2012, 299, 25);
          Baum    b2 = new Baum("Pappel", 2010, 199, 15);
          Liane   l1 = new Liane("Gemeiner Efeu", 1990, 15);
          Strauch s1 = new Strauch("Stechapfel", 1999, 2.5f, true);

          Console.WriteLine("Baum: "    + b1.getInfo());
          Console.WriteLine("Baum: "    + b2.getInfo());
          Console.WriteLine("Liane: "   + l1.getInfo());
          Console.WriteLine("Strauch: " + s1.getInfo());

          /* Objekt vom Typ Gaertnerei erstellen */
          /* create an object from type Gaertnerei */
          Gaertnerei gae1 = new Gaertnerei();

          /* testen der einkaufen Methode einkaufen */
          /* test the einkaufen method */
          gae1.einkaufen(b1);
          gae1.einkaufen(b2);
          gae1.einkaufen(l1);
          gae1.einkaufen(s1);

          /* testen der verkaufen Methode einkaufen */
          /* test the verkaufen method */
          gae1.verkaufen("Eiche" , 2012);

          /* testen der getWoodByLimit Methode einkaufen */
          /* test the getWoodByLimit method */
          List<Gehoelz> tmp;
          tmp = gae1.getWoodByLimit(199.01f);

          /* testen ob die Methode die richtigen Werte zurück liefert */
          /* test if the returnvalues of the method are right */
          Console.WriteLine();
          for(int c=0; c<tmp.Count; c++) {
        Console.WriteLine("[" + c + "] = " + tmp[c].getInfo() );
          }

          /* die Methodeerweiterungen der Klassen Baum und Strauch testen */
          /* test of the extension of the classes Baum and Strauch */
          Console.WriteLine();
          for(int c=0; c<tmp.Count; c++) {
        Gehoelz objtmp = tmp[c];
        if( objtmp is Baum) {
            Baum baum = (Baum)objtmp;
            Console.WriteLine("Instanz war vom Typ Baum: Art=" + baum.getArt() + " maximale Höhe=" + baum.getMaxHoehe() );
        }else if( objtmp is Liane) {
          Liane liane = (Liane)objtmp;
          Console.WriteLine("Instanz war vom Typ Liane : Art=" + liane.getArt() );
        }else if( objtmp is Strauch) {
          Strauch strauch = (Strauch)objtmp;
          Console.WriteLine("Instanz war vom Typ Strauch : Art=" + strauch.getArt() + " ist Giftig=" + strauch.getIstGiftig() );
        }
          }
    }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            List <Pflanze> liste = new List <Pflanze>();

            Blume b1 = new Blume("Gänseblümchen", 1.22, Pflanze.EBodenart.Humus, Pflanze.EFarbe.weiß);
            Blume b2 = new Blume("Rose", 3.1, Pflanze.EBodenart.Sand, Pflanze.EFarbe.rot);
            Blume b3 = new Blume("Tulpe", 2.2, Pflanze.EBodenart.Lehm, Pflanze.EFarbe.orange);
            Blume b4 = new Blume("Gras", 0.8, Pflanze.EBodenart.Humus, Pflanze.EFarbe.weiß);

            Strauch s1 = new Strauch("Dornbusch", 3.3, Pflanze.EBodenart.Humus);
            Strauch s2 = new Strauch("Busch", 2.2, Pflanze.EBodenart.Sand);

            Pflanze[] array = { b1, b2, b3, b4, s1, s2 };

            liste.Add(b1);
            liste.Add(b2);
            liste.Add(b3);
            liste.Add(b4);

            liste.Add(s1);
            liste.Add(s2);

            Console.WriteLine("Vor der Sortierung nach Höhe:");
            foreach (Pflanze p in array)
            {
                Console.WriteLine(p.Höhe);
            }

            Console.WriteLine("Liste nach der Sortierung nach Höhe");
            PflanzenUtil.SortByHeight(array);
            foreach (Pflanze p in array)
            {
                Console.WriteLine(p.Höhe);
            }

            Console.WriteLine("Liste nach der Sortierung nach Boden");
            PflanzenUtil.SortByBoden(liste);
            foreach (Pflanze p in liste)
            {
                Console.WriteLine(p.Bodenart);
            }
        }
Ejemplo n.º 3
0
    public override bool Equals(object value)
    {
        Strauch obj = value as Strauch;

        // Is null?
        if (Object.ReferenceEquals(null, obj))
        {
            return(false);
        }

        // Is the same object?
        if (Object.ReferenceEquals(this, obj))
        {
            return(true);
        }

        // Is the same type?
        if (obj.GetType() != this.GetType())
        {
            return(false);
        }

        return(this.bodenart == obj._bodenart && this.name.Equals(obj._name) && this.hoehe == obj._hoehe && this.GetFarbe() == obj.GetFarbe());
    }