Metainformationen zur Seite
  •  

Würfel Klasse

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
    <title>Würfel Klasse</title>
    <script type="text/javascript" >
        class Wuerfel {  // class
             constructor(size){ //constructor
                this.size = size;                       
            }
 
            //Getter
            getSize(){
                return this.size;           
            }   
 
            getVolume(){
                return this.size * this.size * this.size;           
            }   
 
            getSurface(){
                return this.size * this.size * 6;           
            }
 
            // Setter
            setSize(size){
                this.size=size;         
            }
 
            toString(){
                return  "My size is: " + this.size +"; "
                          +"My Volume is: " + this.getVolume() +"; "
                          +"My Surface is: " + this.getSurface();       
            }           
 
        }
 
        var show = function () {
            w = []  //save in array
            w.push(new Wuerfel(3)); // create object
            w.push(new Wuerfel(4));
            w.push(new Wuerfel(5));
            var outstring = ""; // create the string for div wuerfel
            for (i of w){
                outstring += i.toString() + "<BR>";
            }
            document.getElementById("wuerfel").innerHTML = outstring;
        }
 
    </script>
</head>
 
<body onload="show()">
    <div id="wuerfel"></div>
</body>
</html>