-
Notifications
You must be signed in to change notification settings - Fork 37
Semana 4 - Exercício Classes - Priscila Vieira #27
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,168 @@ | ||
| // NOME: Priscila Baer Gomes Vieira | ||
|
|
||
| class Animal{ | ||
| constructor(nome, idade, cor, social){ | ||
| this.nome = nome | ||
| this.idade = idade | ||
| this.cor = cor | ||
| this.consultas = [] | ||
| this.social = social | ||
| } | ||
|
|
||
| consultar(){ | ||
| this.consultas.unshift(new Date()) | ||
| } | ||
|
|
||
| brincar(){ | ||
| console.log("Hora de brincar!!") | ||
| } | ||
|
|
||
| acariciar(){ | ||
| console.log("Hora do carinho") | ||
| } | ||
|
|
||
| alimentar(comida){ | ||
| console.log(`${this.nome} recebeu ${comida}`) | ||
| } | ||
| } | ||
|
|
||
| class Domesticado extends Animal{ | ||
|
|
||
| constructor(nome, idade, cor, social, castrado){ | ||
| super(nome, idade, cor, social) | ||
| this.castrado = castrado | ||
| this.vacinas = [] | ||
| } | ||
|
|
||
|
|
||
| vacinar(vacina){ | ||
| this.vacinas.push(vacina) | ||
| super.consultar() | ||
|
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. Show que usou o super! No meu eu não usei, mas acho que o teu jeito faz mais sentido. O meu eu chamei consultar numa classe Animal, depois nas classes Cachorro, Gato etc eu chamei no construtor o this.consultas e nos métodos eu coloquei this.consultar(), não coloquei o super, mas vou fazer assim da próxima vez! |
||
| } | ||
|
|
||
| castrar(){ | ||
| if(this.castrado){ | ||
| console.log(`OPA!!! ${this.nome} já foi castrado!`) | ||
| } else{ | ||
| this.castrado = true | ||
| super.consultar() | ||
| console.log(`${this.nome} foi castrado!`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Gato extends Domesticado{ | ||
| constructor(nome, idade, cor, social, castrado){ | ||
| super(nome, idade, cor, social, castrado) | ||
| this.externo = false | ||
| } | ||
|
|
||
| miar(){ | ||
| console.log("miau miaauuu") | ||
| } | ||
|
|
||
| alimentar(comida){ | ||
| const comidasFavoritas = ["frango","sachê","peixe"] | ||
|
|
||
| if(comidasFavoritas.includes(comida)){ | ||
|
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. perfeito o includes, eu achei que conseguiria usar no meu, mas não teve jeito. Olhando o teu código, agora entendi! |
||
| this.social = true | ||
| super.alimentar(comida) | ||
| console.log(", uma de suas favoritas e agora deixa acariciar") | ||
| }else{ | ||
| console.log(`${comida} não é a comida favorita de ${this.nome}`) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| acariciar(){ | ||
| super.acariciar() | ||
| if(this.social){ | ||
| console.log("ron ron ron") | ||
| }else{ | ||
| console.log(`${this.nome} não é sociável, está silvando. Se der sua comida favorita, ficará sociável e deixará ser acariciado`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class Cachorro extends Domesticado{ | ||
| #ferido | ||
|
|
||
| constructor(nome, idade, cor, social, castrado, raca){ | ||
| super(nome, idade, cor, social, castrado) | ||
| this.#ferido = true | ||
| this.raca = raca | ||
| } | ||
|
|
||
| latir(){ | ||
| console.log("au aauuu") | ||
| } | ||
|
|
||
| acariciar(){ | ||
| super.acariciar() | ||
| console.log("aufff") | ||
| } | ||
|
|
||
| brincar(){ | ||
| super.brincar() | ||
| if(this.#ferido){ | ||
| console.log(`${this.nome} não está bem, não veio brincar, vamos ao veterinário!`) | ||
| this.#ferido = false | ||
| super.consultar() | ||
| }else{ | ||
| console.log(`Pega a bolinha ${this.nome}!!`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Papagaio extends Animal{ | ||
| constructor(nome, idade, cor, social) | ||
| super(nome, idade, cor, social) | ||
| } | ||
|
|
||
| falar(){ | ||
| console.log('Oi oi td bem?') | ||
| } | ||
|
|
||
| acariciar(){ | ||
| super.acariciar() | ||
| console.log("Prrrll") | ||
| } | ||
|
|
||
| brincar(){ | ||
| super.brincar() | ||
| falar() | ||
| } | ||
|
|
||
| alimentar(comida){ | ||
| super.alimentar(comida) | ||
| falar() | ||
| } | ||
| } | ||
|
|
||
| class Hamster extends Animal{ | ||
| constructor(nome, idade, cor, social) | ||
| super(nome, idade, cor, social) | ||
| this.tipo= "sírio" | ||
| } | ||
|
|
||
| consultar(){ | ||
| brincar() | ||
| super.consultar() | ||
| } | ||
|
|
||
| brincar(){ | ||
| console.log(`Brincando com ${this.nome}´) | ||
| } | ||
| } | ||
|
|
||
| function chamar(listaAnimais) { | ||
| const listaAnimaisQueResponderam = [] | ||
|
|
||
| listaAnimais.forEach(animal => { | ||
| if(animal.social){ | ||
| listaAnimaisQueResponderam.push(animal) | ||
| } | ||
| }) | ||
| return listaAnimaisQueResponderam | ||
| } | ||
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.
Aaaah legal! Tu separou por classes os domésticos! Eu não fiz isso no meu, mas achei uma ótima ideia!