using System;
public abstract class Figura
{
private string idFigura;
public Figura (string idFigura)
{
IdFigura = idFigura; // asigna el valor de idFigura a la propiedad IdFigura
}
public string IdFigura
{
get
{
return idFigura;
}
set
{
idFigura = value;
}
}
// La propiedad Area es de sólo-lectura
public abstract double Area
{
get;
}
public override string ToString ()
{
return IdFigura + " Área = " + string.Format("{0:F2}",Area);
}
}
public class Cuadrado : Figura
{
private int lado;
public Cuadrado (int lado, string idFigura) : base (idFigura)
{
this.lado = lado;
}
public override double Area
{
get
{
return lado * lado;
}
}
}
public class Circulo : Figura
{
private int radio;
public Circulo (int radio, string idFigura) : base (idFigura)
{
this.radio = radio;
}
public override double Area
{
get
{
return radio * radio * Math.PI;
}
}
}
public class Rectangulo : Figura
{
private int ancho;
private int alto;
public Rectangulo (int ancho, int alto, string idFigura) : base (idFigura)
{
this.ancho = ancho;
this.alto = alto;
}
public override double Area
{
get
{
return ancho * alto;
}
}
}
public class PruebaFigura
{
public static void Main ()
{
Figura[] figuras =
{
new Cuadrado (5, "Cuadrado #1"),
new Circulo (3, "Círculo #1"),
new Rectangulo (4, 5, "Rectángulo #1")
};
Console.WriteLine ("Colección de Figuras");
foreach (Figura figura in figuras)
{
Console.WriteLine (figura.ToString());
}
}
}
dXNpbmcgU3lzdGVtOwoKcHVibGljIGFic3RyYWN0IGNsYXNzIEZpZ3VyYQp7CiAgICBwcml2YXRlIHN0cmluZyBpZEZpZ3VyYTsKICAgIAogICAgcHVibGljIEZpZ3VyYSAoc3RyaW5nIGlkRmlndXJhKQogICAgewogICAgICAgIElkRmlndXJhID0gaWRGaWd1cmE7ICAgICAgICAgICAgLy8gYXNpZ25hIGVsIHZhbG9yIGRlIGlkRmlndXJhIGEgbGEgcHJvcGllZGFkIElkRmlndXJhCiAgICB9CiAgICAKICAgIHB1YmxpYyBzdHJpbmcgSWRGaWd1cmEKICAgIHsKICAgICAgICBnZXQKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBpZEZpZ3VyYTsKICAgICAgICB9CiAgICAgICAgc2V0CiAgICAgICAgewogICAgICAgICAgICBpZEZpZ3VyYSA9IHZhbHVlOwogICAgICAgIH0KICAgIH0KICAgIAogICAgLy8gTGEgcHJvcGllZGFkIEFyZWEgZXMgZGUgc8OzbG8tbGVjdHVyYQogICAgcHVibGljIGFic3RyYWN0IGRvdWJsZSBBcmVhCiAgICB7CiAgICAgICAgZ2V0OwogICAgfQogICAgCiAgICBwdWJsaWMgb3ZlcnJpZGUgc3RyaW5nIFRvU3RyaW5nICgpCiAgICB7CiAgICAgICAgcmV0dXJuIElkRmlndXJhICArICIgw4FyZWEgPSAiICsgc3RyaW5nLkZvcm1hdCgiezA6RjJ9IixBcmVhKTsKICAgIH0KfQoKcHVibGljIGNsYXNzIEN1YWRyYWRvIDogRmlndXJhCnsKICAgIHByaXZhdGUgaW50IGxhZG87CiAgICAKICAgIHB1YmxpYyBDdWFkcmFkbyAoaW50IGxhZG8sIHN0cmluZyBpZEZpZ3VyYSkgOiBiYXNlIChpZEZpZ3VyYSkKICAgIHsKICAgICAgICB0aGlzLmxhZG8gPSBsYWRvOwogICAgfQogICAgCiAgICBwdWJsaWMgb3ZlcnJpZGUgZG91YmxlIEFyZWEKICAgIHsKICAgICAgICBnZXQKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBsYWRvICogbGFkbzsKICAgICAgICB9CiAgICB9Cn0KIApwdWJsaWMgY2xhc3MgQ2lyY3VsbyA6IEZpZ3VyYQp7CiAgICBwcml2YXRlIGludCByYWRpbzsKICAgIAogICAgcHVibGljIENpcmN1bG8gKGludCByYWRpbywgc3RyaW5nIGlkRmlndXJhKSA6IGJhc2UgKGlkRmlndXJhKQogICAgewogICAgICAgIHRoaXMucmFkaW8gPSByYWRpbzsKICAgIH0KICAgIAogICAgcHVibGljIG92ZXJyaWRlIGRvdWJsZSBBcmVhCiAgICB7CiAgICAgICAgZ2V0CiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gcmFkaW8gKiByYWRpbyAqIE1hdGguUEk7CiAgICAgICAgfQogICAgfQp9CgpwdWJsaWMgY2xhc3MgUmVjdGFuZ3VsbyA6IEZpZ3VyYQp7CiAgICBwcml2YXRlIGludCBhbmNobzsKICAgIHByaXZhdGUgaW50IGFsdG87CiAgICAKICAgIHB1YmxpYyBSZWN0YW5ndWxvIChpbnQgYW5jaG8sIGludCBhbHRvLCBzdHJpbmcgaWRGaWd1cmEpIDogYmFzZSAoaWRGaWd1cmEpCiAgICB7CiAgICAgICAgdGhpcy5hbmNobyA9IGFuY2hvOwogICAgICAgIHRoaXMuYWx0byA9IGFsdG87CiAgICB9CiAgICAKICAgIHB1YmxpYyBvdmVycmlkZSBkb3VibGUgQXJlYQogICAgewogICAgICAgIGdldAogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIGFuY2hvICogYWx0bzsKICAgICAgICB9CiAgICB9Cn0KCnB1YmxpYyBjbGFzcyBQcnVlYmFGaWd1cmEKewogICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4gKCkKICAgIHsKICAgICAgICBGaWd1cmFbXSBmaWd1cmFzID0gCiAgICAgICAgeyAKICAgICAgICAgICAgbmV3IEN1YWRyYWRvICg1LCAiQ3VhZHJhZG8gIzEiKSwgCiAgICAgICAgICAgIG5ldyBDaXJjdWxvICgzLCAiQ8OtcmN1bG8gIzEiKSwgCiAgICAgICAgICAgIG5ldyBSZWN0YW5ndWxvICg0LCA1LCAiUmVjdMOhbmd1bG8gIzEiKQogICAgICAgIH07CiAgICAgICAgCiAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJDb2xlY2Npw7NuIGRlIEZpZ3VyYXMiKTsKICAgICAgICAKICAgICAgICBmb3JlYWNoIChGaWd1cmEgZmlndXJhIGluIGZpZ3VyYXMpCiAgICAgICAgewogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoZmlndXJhLlRvU3RyaW5nKCkpOwogICAgICAgIH0KICAgIH0KfQ==