\-- Rectangle | |---- width ivar | |---- height ivar
Rectangle
width ivars
height
Rectangle
width ivars
height
constructor(w, h) { super(); this.width = (w !== undefined) ? w : 0; this.height = (h !== undefined) ? h : 0; this.setAsNumeric('width', 'height'); }
getWidth() {
return this.width;
}
getHeight() {
return this.height;
}
getDiagonal() { const w = this.width, h = this.height; return Math.sqrt(w*w + h*h); }
setWidth(value) {
this.width = value;
}
setHeight(value) {
this.height = value;
}
getArea() {
return this.width * this.height;
}
getPerimeter() {
return 2 * (this.width + this.height);
}
flip() { const w = this.width; this.width = this.height; this.height = w; }
multiply(factor) {
this.width = this.width * factor;
this.height = this.height * factor;
}
toString() {
return '' + this.getWidth() + 'x' + this.getHeight()
+ ' area=' + this.getArea();
}
class Rectangle extends Model { /*ivars width height*/ //------------------------------------------------ constructor(w, h) { super(); this.width = (w !== undefined) ? w : 0; this.height = (h !== undefined) ? h : 0; this.setAsNumeric('width', 'height'); } //------------------------------------------------ //Getters (Basic) getWidth() { return this.width; } getHeight() { return this.height; } //------------------------------------------------ //Setters setWidth(value) { this.width = value; } setHeight(value) { this.height = value; } //------------------------------------------------ //Calcs getArea() { return this.width * this.height; } getPerimeter() { return 2 * (this.width + this.height); } getDiagonal() { const w = this.width, h = this.height; return Math.sqrt(w*w + h*h); } //------------------------------------------------ //Actions flip() { const w = this.width; this.width = this.height; this.height = w; } multiply(factor) { this.width = this.width * factor; this.height = this.height * factor; } //------------------------------------------------ //Common toString() { return '' + this.getWidth() + 'x' + this.getHeight() + ' area=' + this.getArea(); } }