diff --git b/EjemploInterface.java a/EjemploInterface.java new file mode 100644 index 0000000..889aed6 --- /dev/null +++ a/EjemploInterface.java @@ -0,0 +1,147 @@ +public class EjemploInterface { + public static void main(String[] args) { + Forma cir = new Circulo( "Rojo",5.f); + Forma cuad = new Rectangulo("Amarillo", 5.f, 3.f); + Cartel cartel1 = new Cartel(cir, "Peligro"); + Cartel cartel2 = new Cartel(cuad, "Atencion"); + System.out.println(cartel1.cuadraTexto()); + System.out.println(cartel2.cuadraTexto()); + + } +} + +interface Forma{ + + public String getColor(); + + public void setColor(String color); + + public float getPerimetro(); + + public float getArea(); + + public float getLongitud(); +} + + +class Cartel{ + + private Forma forma; + private String texto; + + public Cartel(Forma forma, String texto) { + this.forma = forma; + this.texto = texto; + } + + public Forma getForma(){ + return this.forma; + } + + public void setForma(Forma forma){ + this.forma = forma; + } + + public String getTexto(){ + return this.texto; + } + + public void setTexto(String texto){ + this.texto = texto; + } + + public boolean cuadraTexto(){ + return this.texto.length() < this.forma.getLongitud(); + } +} + +class Circulo implements Forma{ + private String color; + private float radio; + + public Circulo(String color, float radio) { + this.color = color; + this.radio = radio; + } + + @Override + public String getColor() { + + return color; + } + + @Override + public void setColor(String color) { + this.color = color; + + } + + @Override + public float getPerimetro() { + + return (float)Math.PI*2*radio; + } + + @Override + public float getArea() { + + return (float)Math.PI*radio*radio; + } + + @Override + public float getLongitud() { + // TODO Auto-generated method stub + return 2*radio; + } + +} + +class Rectangulo implements Forma{ + private String color; + private float largo; + private float ancho; + + public Rectangulo(String color, float largo, float ancho) { + this.color = color; + this.largo = largo; + this.ancho = ancho; + } + + @Override + public String getColor() { + + return color; + } + + @Override + public void setColor(String color) { + this.color = color; + + } + + @Override + public float getPerimetro() { + + return 2*(largo+ancho); + } + + @Override + public float getArea() { + + return largo*ancho; + } + + public float getAncho() { + return ancho; + } + public float getLongitud() { + return largo; + } + public void setAncho(float ancho) { + this.ancho = ancho; + } + public void setLongitud(float largo) { + this.largo = largo; + } + +} \ No newline at end of file