-
-
Notifications
You must be signed in to change notification settings - Fork 179
OOP exercise #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OOP exercise #93
Changes from 4 commits
24f2253
2a431b0
4bdd7d6
a40c18c
2a6615e
48b9477
ac74310
e22735b
368ab78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| class Mammal { | ||
| constructor (name, gender, legs, saying) { | ||
| this.species = 'mammal'; | ||
| this.name = name; | ||
| this.gender = gender; | ||
| this.legs = legs; | ||
| this.saying = saying; | ||
| } | ||
|
|
||
| tellAboutClass() { | ||
| return `${this.saying} My name is ${this.name}. I'm ${this.species} ${this.gender}. I have ${this.legs} legs.`; | ||
| } | ||
| } | ||
|
|
||
| class Human extends Mammal{ | ||
| constructor (name, gender, saying) { | ||
| super(name, gender); | ||
| this.species = 'human'; | ||
| this.legs = 2; | ||
| this.hands = 2; | ||
| this.saying = saying; | ||
| } | ||
|
|
||
| tellAboutClass() { | ||
| return `${super.tellAboutClass()} I have ${this.hands} hands.`; | ||
| } | ||
| } | ||
|
|
||
| class Man extends Human { | ||
| constructor (name, saying = 'Hello.') { | ||
| super(name, saying); | ||
| this.gender = 'male'; | ||
| this.saying = saying; | ||
| } | ||
| } | ||
|
|
||
| class Woman extends Human { | ||
| constructor (name, saying = 'Hi') { | ||
| super(name, saying); | ||
| this.gender = 'female'; | ||
| this.saying = saying; | ||
|
||
| } | ||
| } | ||
|
|
||
| class Dog extends Mammal { | ||
| constructor (name, gender, saying = 'woof') { | ||
| super(name, gender); | ||
| this.species = 'dog'; | ||
| this.legs = 4; | ||
| this.saying = saying; | ||
| } | ||
| } | ||
|
|
||
| class Cat extends Mammal { | ||
| constructor (name, gender, saying = 'Meow') { | ||
| super(name, gender); | ||
| this.species = 'cat'; | ||
| this.legs = 4; | ||
| this.saying = saying; | ||
| } | ||
| } | ||
|
|
||
| const john = new Man('John'); | ||
| const cassy = new Woman('Cassy', 'Hi!'); | ||
| const ralph = new Dog('Ralph', 'male', 'Woooooof'); | ||
| const aimi = new Cat('Aimi', 'female', 'Meeeeeeoooooooow'); | ||
|
|
||
| const inhabitants = [john, cassy, ralph, aimi]; | ||
|
|
||
| inhabitants.forEach( item => print(item.tellAboutClass())); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mammalclass should store values that are exclusive to it. Does every mammal have hands or wings?