Advertisement
kstoyanov

05. * Computer

Oct 16th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     class Keyboard {
  3.         constructor(manufacturer, responseTime) {
  4.             this.manufacturer = manufacturer;
  5.             this.responseTime = responseTime;
  6.         }
  7.     }
  8.  
  9.     class Monitor {
  10.         constructor(manufacturer, width, height) {
  11.             this.manufacturer = manufacturer;
  12.             this.width = width;
  13.             this.height = height;
  14.         }
  15.     }
  16.  
  17.     class Battery {
  18.         constructor(manufacturer, expectedLife) {
  19.             this.manufacturer = manufacturer;
  20.             this.expectedLife = expectedLife;
  21.         }
  22.     }
  23.  
  24.     class Computer {
  25.         constructor(manufacturer, processorSpeed, ram, hardDiskSpace) {
  26.             if (new.target === Computer) {
  27.                 throw new Error("Can not instantiate directly.")
  28.             }
  29.             this.manufacturer = manufacturer;
  30.             this.processorSpeed = processorSpeed;
  31.             this.ram = ram;
  32.             this.hardDiskSpace = hardDiskSpace;
  33.         }
  34.     }
  35.  
  36.     class Laptop extends Computer {
  37.         constructor(manufacturer, processorSpeed, ram, hardDiskSpace, weight, color, battery) {
  38.             super(manufacturer, processorSpeed, ram, hardDiskSpace);
  39.             this.weight = weight;
  40.             this.color = color;
  41.             this.battery = battery;
  42.         }
  43.  
  44.         get battery() {
  45.             return this._battery;
  46.         }
  47.  
  48.         set battery(value) {
  49.             if (value instanceof Battery) {
  50.                 this._battery = value;
  51.             } else {
  52.                 throw new TypeError();
  53.             }
  54.         }
  55.     }
  56.  
  57.     class Desktop extends Computer {
  58.         constructor(manufacturer, processorSpeed, ram, hardDiskSpace, keyboard, monitor ) {
  59.             super(manufacturer, processorSpeed, ram, hardDiskSpace);
  60.             this.keyboard = keyboard;
  61.             this.monitor = monitor;
  62.         }
  63.         get keyboard() {
  64.             return this._keyboard;
  65.         }
  66.  
  67.         set keyboard(value) {
  68.             if (value instanceof Keyboard) {
  69.                 this._keyboard = value;
  70.             } else {
  71.                 throw new TypeError();
  72.             }
  73.         }
  74.  
  75.         get monitor() {
  76.             return this._monitor;
  77.         }
  78.  
  79.         set monitor(value) {
  80.             if (value instanceof Monitor) {
  81.                 this._monitor = value;
  82.             } else {
  83.                 throw new TypeError();
  84.             }
  85.         }
  86.     }
  87.  
  88.     return {
  89.         Battery,
  90.         Keyboard,
  91.         Monitor,
  92.         Computer,
  93.         Laptop,
  94.         Desktop
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement