Beebeebee 의사코드 작성

코린이·2023년 5월 12일
0

프로토타입

클래스/인스턴스

생성자 constructor
메서드 extends super

Grub의 코드

class Grub  {
  // TODO..
  // 나이 : 0 / 색깔 속성: 핑크/ 음식 속성 : jelly
  // eat의 리턴값 Mmmmmmmmm jelly

  constructor() {
    this.age = 0;
    this.color = 'pink';
    this.food = 'jelly';
  }
    eat (){
      return 'Mmmmmmmmm jelly'
    }
}

module.exports = Grub;

Bee의 코드

const Grub = require('./1-Grub');

class Bee extends Grub{
  // TODO..
  // 생성자 
  // 속성 나이:5, 색깔 :노란색, 음식 : jelly, 직업: keep on growing
  //eat 을 함수로. 

  constructor(){
    super();
    this.age = 5;
    this.color = "yellow";
    this.food = "jelly";
    this.job = "Keep on growing";
  };
}

const bee = new Bee();
bee.eat(); 

module.exports = Bee;
코드를 입력하세요

ForagerBee의 코드

const Bee = require('./2-Bee');

class ForagerBee extends Bee {
  // TODO..
  // 나이 10 , job은 find pollen ,color 는 bee로부터 상속 
  //food 속성은 Grub 으로부터 상속
  //canFly` 속성은 `true'
  //`treasureChest` 속성은 빈 배열 `[]`
  //'`forage` 메서드를 통해 `treasureChest` 속성에 보물을 추가할 수 있어야 합니다' 배열이니까 .push 메서드 이용 
  
  constructor (){

  super()
  this.age = 10;
  this.job = 'find pollen';
  this.canFly =true;
  this.treasureChest = [];  
}

forage(pollen){
  this.treasureChest.push(pollen);
}
}

module.exports = ForagerBee;코드를 입력하세요

HoneyMakerBee 의 코드

const Bee = require('./2-Bee');

//의사코드 age : 10 /job make honey/
/color 속성은 bee로부터 상속/
/food 속성은 Grub으로부터 상속/
/eat 메서드는 grub으로부터 상속/
/honeypot의 속성은 0
/`makeHoney` 메서드는 `honeyPot`에 1씩 추가
/`giveHoney` 메서드는 `honeyPot`에 1씩 뺍니다'

class HoneyMakerBee extends Bee{
  constructor(age = 10, color, food, job = 'make honey') {
    super(age, color, food, job);
    this.age = 10;
    this.job = 'make honey';
    this.honeyPot = 0;
  }

  makeHoney() {
    this.honeyPot += 1;
  }

  giveHoney() {
    this.honeyPot -= 1;
  }
}

module.exports = HoneyMakerBee;
profile
코린이

0개의 댓글