class Animal{
constructor (color) {
this.color = color;
}
eat(){
console.log('먹는다!');
}
sleep(){
console.log('잔다!');
}
}
class Dog extends Animal{
play(){
console.log('논다!');
}
}
const Rucy = new Dog('white');
console.log(Rucy);
Rucy.eat();
Rucy.sleep();
Rucy.play();
class Cat extends Animal{
constructor (color, name){
super(color);
this.name = name;
}
eat(){
console.log('맛있게 먹는다!');
}
}
const Horang = new Cat('black', '호랑');
console.log(Horang);
Horang.eat();
console.log('---------------------------------------------------');
// 문제
// 정직원, 아르바이트를 나타낼수 있는 클래스를 생성
// FullTimeEmployee, PartTimeEmployee
// 직원의 정보: 이름, 부서명, 한달 근무시간 (프로퍼티)
// 급여: 정직원(20000), 알바(10000)
// 매달 직원들의 정보를 이용해서 한달 급여를 계산하는 메소드를 구현(calculatePay())
// ex) kim.calculatePay() -> 한달 급여
// class Employee {
// // #name
// // #bu
// // #time
// // #pay
// constructor(name, bu, pay, time){
// this.name = name;
// this.bu = bu;
// this.time = time;
// this.pay = pay;
// }
// calculatePay(pay, time){
// if (this.time <= 0){
// return `급여가 없습니다`
// }else{
// console.log(this.pay * this.time);
// }
// }
// }
// class FullTimeEmployee extends Employee{
// }
// class PartTimeEmployee extends Employee{
// }
// const noname = new FullTimeEmployee('김직원', '인사팀', 20000, 120)
// const kim = new PartTimeEmployee('김알바', '인사팀', 10000, 80)
// noname.calculatePay();
// kim.calculatePay();
// console.log(noname);
// console.log(kim);
console.log('-----------------------');
console.log('선생님 답안');
class Employee {
constructor(name, department, hourPerMonth, payRate) {
this.name = name;
this.department = department;
this.hourPerMonth = hourPerMonth;
this.payRate = payRate;
}
calculatepay(){
return this.hourPerMonth * this.payRate;
}
}
class FullTimeEmployee extends Employee{
static PAY_RATE = 20000;
constructor(name, department, hourPerMonth){
super(name, department, hourPerMonth, FullTimeEmployee.PAY_RATE)
}
}
class PartTimeEmployee extends Employee{
static PAY_RATE = 10000;
constructor(name, department, hourPerMonth){
super(name, department, hourPerMonth, PartTimeEmployee.PAY_RATE)
}
}
const kim = new FullTimeEmployee('김사과', '개발자', 160);
const Orange = new PartTimeEmployee('오랜지', '디자이너', 100);
console.log(kim.calculatepay());
console.log(Orange.calculatepay());