Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- class Figure {
- units = {
- m: 0.01,
- cm: 1,
- mm: 10
- }
- defaultUnit;
- constructor(unit = "cm") {
- this.defaultUnit = unit;
- }
- get area() { return NaN }
- changeUnits(x) { this.defaultUnit = x; };
- calcWidthUnit(x) { return x * this.units[this.defaultUnit]; }
- toString() { return `Figures units: ${this.defaultUnit} Area: ${this.area}` }
- }
- class Circle extends Figure {
- radius = 0;
- constructor(r, ...rest) {
- super(...rest);
- this.radius = r;
- }
- get area() { return Math.PI * Math.pow(this.calcWidthUnit(this.radius), 2); }
- toString() { return super.toString() + ` - radius: ${this.calcWidthUnit(this.radius)}` }
- }
- class Rectangle extends Figure {
- width = 0;
- height = 0;
- constructor(w, h, ...rest) {
- super(...rest);
- this.width = w;
- this.height = h;
- }
- get h() { return this.calcWidthUnit(this.height); }
- get w() { return this.calcWidthUnit(this.width); }
- get area() { return this.w * this.h; }
- toString() { return super.toString() + ` - width: ${this.w}, height: ${this.h}` }
- }
- return {Figure, Circle, Rectangle}
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement