-
Notifications
You must be signed in to change notification settings - Fork 37
Carol marquezini - exercício da semana 4 #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,93 @@ | ||
| class Animal { | ||
| constructor(nome, idade, cor) { | ||
| this.nome = nome; | ||
| this.idade = idade; | ||
| this.cor = cor; | ||
| this.consultas = []; | ||
| } | ||
|
|
||
| consultar() { | ||
| this.consultas.push(new Date()); | ||
| } | ||
|
|
||
| brincar(brincadeira) { | ||
| console.log(`brincando de ${brincadeira} com ${this.nome}`); | ||
| } | ||
|
|
||
| acariciar() { | ||
| console.log(`Você está acariciando o(a) ${this.nome} *-*`); | ||
| } | ||
|
|
||
| alimetar() { | ||
| console.log(`Você está alimentando o(a) ${this.nome} :)`); | ||
| } | ||
| } | ||
|
|
||
| class Domestico extends Animal { | ||
| constructor(nome, idade, cor) { | ||
| super(nome, idade, cor); | ||
|
|
||
| this.castrado = false; | ||
| this.vacinas = []; | ||
| this.consultas = []; | ||
| } | ||
|
|
||
| vacinar(vacina) { | ||
| this.vacinas.push(vacina); | ||
| this.consultar(); | ||
| } | ||
|
|
||
| castrar(data) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O método está funcionando direitinho, faltou só gerar o erro, se o animal já tinha sido castrado. Acredito que a (data) não seja necessária. Porque tu já está fazendo um push na data no método consultar e funciona certinho. |
||
| this.castrado = true; | ||
| this.consultar(data); | ||
| } | ||
| } | ||
|
|
||
| class Gatos extends Domestico { | ||
| constructor(nome, idade, cor) { | ||
| super(nome, idade, cor); | ||
| } | ||
|
|
||
| miar() { | ||
| console.log('miau miau'); | ||
| } | ||
|
|
||
| alimetar(comida) { | ||
| if ((comida == 'frango') | (comida == 'sachê') | (comida == 'peixe')) { | ||
| console.log('gato alimetado e sociável!!!'); | ||
| } else { | ||
| console.log('gato alimentado mas não sociável!'); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let charmoso = new Gatos('Charmoso', 12, 'branco'); //idade em meses | ||
|
|
||
| class Cachorros extends Domestico { | ||
| #ferido; | ||
|
|
||
| constructor(nome, idade, cor, raca) { | ||
| super(nome, idade, cor); | ||
|
|
||
| this.raca = raca; | ||
| this.#ferido = false; | ||
| } | ||
|
|
||
| latir() { | ||
| console.log('auu auu'); | ||
| } | ||
|
|
||
| mudarFerido(ferido) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gostei de este método de mudar o estado do animal <3 |
||
| this.#ferido = ferido; | ||
| } | ||
|
|
||
| brincar(brincadeira) { | ||
| if (this.#ferido) { | ||
| console.log('cachorro feriado, não pode brincar.'); | ||
| return; | ||
| } | ||
| console.log(`brincando de ${brincadeira} com ${this.nome}`); | ||
| } | ||
| } | ||
|
|
||
| let boris = new Cachorros('Bóris', 36, 'branco', 'shitzu'); //idade em meses | ||
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.
aqui tu poderia ter economizado no this.consultas = [], já que ele também se estende da classe animal.