Sol figuras herencia
De wikiserver
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
class Figura {
constructor(color) {
this.color = color;
}
set cambioColor(c) {
this.color = c;
}
get obtenerColor()
{
return this.color;
}
mostrar() {
// document.write("******Figuraº**********");
document.write("</br>");
document.write("Color: " + this.obtenerColor+"</br>");
document.write("</br>");
}
}
class cuadrado extends Figura {
constructor(color, lado) {
super(color);
this.lado = lado;
}
set cambioLado(l) {
this.lado = l;
}
get obtenerLado()
{
return this.lado;
}
get calculaArea() {
return this.lado * this.lado;
}
mostrar() {
// document.write("******Cuadrado**********");
document.write("</br>");
super.mostrar();
document.write("Area cuadrado " + this.calculaArea+"</br>");
document.write("</br>");
}
}
class rectangulo extends Figura {
constructor(color, lado, altura) {
super(color);
this.base = lado;
this.altura = altura;
}
set cambioBase(b) {
this.base = b;
}
get obtenerBase()
{
return this.base;
}
set cambioAltura(a) {
this.altura = a;
}
get obtenerAltura()
{
return this.altura;
}
get calculaArea() {
return this.base * this.altura;
}
mostrar() {
// document.write("******Rectangulo**********");
document.write("</br>");
super.mostrar();
document.write("Area rectangulo" + this.calculaArea+"</br>");
document.write("</br>");
}
}
class triangulo extends rectangulo {
constructor(color, base, altura) {
super(color, base, altura);
}
mostrar() {
// document.write("******Triangulo**********");
document.write("</br>");
super.mostrar();
document.write("Obtener Base" + super.obtenerBase+"</br>");
document.write("Obtener Altura" + super.obtenerAltura+"</br>");
document.write("Area triangulo" + super.calculaArea / 2+"</br>");
document.write("</br>");
}
}
var f = new Figura("Rojo");
f.mostrar();
var c = new cuadrado("Verde", 1);
c.mostrar();
var r = new rectangulo("azul", 2, 3);
r.mostrar();
var t = new triangulo("orange", 4, 5);
t.mostrar();
</script>
</head>
<body>
<div>TODO write content</div>
</body>
</html>