Last active
May 23, 2020 15:05
-
-
Save felipe1181/92cd22edf530f9a150c6664be64ab57b to your computer and use it in GitHub Desktop.
Software engineering exercise, OO programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @exports | |
* @class Cliente | |
* | |
*/ | |
class Cliente { | |
constructor({id, nome}) { | |
this.id = id; | |
this.nome = nome; | |
} | |
toString() { | |
console.log('id:',this.id); | |
console.log('Nome:',this.nome); | |
} | |
} | |
module.exports = Cliente; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Cliente = require('./Cliente'); | |
const Item = require('./Item'); | |
const Venda = require('./Venda'); | |
const cliente = new Cliente({id:1,nome:'felipe ferraresi'}) | |
const venda = new Venda({id:1,Cliente:cliente}); | |
const arroz = new Item({ id:1, nome:'arroz pop',quantidade:5,preco:2 })// id,nome,preço,quantidade | |
const feijao = new Item({ id:2, nome:'feijão de corda',quantidade:7,preco:4 })// id,nome,preço,quantidade | |
venda.adicionarCarrinhoCompras(arroz); | |
venda.adicionarCarrinhoCompras(feijao); | |
venda.finalizarCompra(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @exports | |
* @class Item | |
* | |
*/ | |
class Item { | |
constructor({id, nome,quantidade,preco}) { | |
this.id = id; | |
this.nome = nome; | |
this.quantidade = quantidade; | |
this.preco = preco; | |
} | |
toString() { | |
console.log('id:',this.id); | |
console.log('Nome:',this.nome); | |
console.log('Preço do produto:',this.preco,'R$ | ','Valor total:',this.getValorTotal()); | |
console.log('Quantidade do produto:',this.quantidade); | |
} | |
getValorTotal(){ | |
return this.preco*this.quantidade; | |
} | |
} | |
module.exports = Item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Software engineering exercise, OO programming |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @exports | |
* @class Venda | |
* | |
*/ | |
class Venda { | |
carrinhoCompras = []; | |
constructor({id,Cliente}) { | |
this.id = id; | |
this.Cliente = Cliente; | |
} | |
adicionarCarrinhoCompras(Item){ | |
this.carrinhoCompras.push(Item); | |
} | |
finalizarCompra() { | |
console.log('================== VENDA ====================') | |
console.log('====== CLIENTE ======'); | |
this.Cliente.toString() | |
console.log('====== ITENS ======'); | |
this.carrinhoCompras.forEach(item => { | |
item.toString(); | |
}); | |
const precoFinal = this.carrinhoCompras.reduce((accumulator, item) => accumulator + item.getValorTotal(),0); | |
console.log('Preço final:',precoFinal); | |
} | |
} | |
module.exports = Venda; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment