commit 10a916b1192014d51e6c5c5ee1f2a07b3f11f19a Author: Luiz F. Picolo Date: Mon May 27 21:48:24 2024 -0400 CODIGO AZUL diff --git a/index.js b/index.js new file mode 100644 index 0000000..12c7014 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +import PessoaFisica from "./pessoa_fisica.js"; +import PessoaJuridica from "./pessoa_juridica.js"; + +const pessoa_fisica = new PessoaFisica("Picolo Fisico"); +pessoa_fisica.cpf = "000000000"; +console.log(pessoa_fisica.mostrarDados()) + +const pessoa_juridica = new PessoaJuridica("Picolo Jurídico"); +pessoa_juridica.cnpj = "111111111"; +console.log(pessoa_juridica.mostrarDados()) \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..619e42e --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "poo", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Luiz Picolo ", + "license": "MIT" +} diff --git a/pessoa.js b/pessoa.js new file mode 100644 index 0000000..6c9232f --- /dev/null +++ b/pessoa.js @@ -0,0 +1,30 @@ +class Pessoa { + #_nome; + #_sobrenome; + + constructor(nome){ + if (this.constructor === Pessoa){ + throw new Error("Classe abstrata não pode ser instanciada diretamente."); + } + + this.#_nome = nome + } + + set sobrenome(sobrenome){ + this.#_sobrenome = sobrenome + } + + get sobrenome(){ + return this.#_sobrenome + } + + get nome(){ + return this.#_nome + } + + mostrarDados(){ + throw new Error("Esse método deve ser implementado"); + } +} + +export default Pessoa; \ No newline at end of file diff --git a/pessoa_fisica.js b/pessoa_fisica.js new file mode 100644 index 0000000..1c38b2a --- /dev/null +++ b/pessoa_fisica.js @@ -0,0 +1,23 @@ +import Pessoa from './pessoa.js' + +class PessoaFisica extends Pessoa { + #_cpf + + constructor(nome) { + super(nome) + } + + set cpf(cpf) { + this.#_cpf = cpf + } + + get cpf() { + return this.#_cpf + } + + mostrarDados(){ + return `Meus dados são: ${this.nome} e ${this.cpf}` + } +} + +export default PessoaFisica \ No newline at end of file diff --git a/pessoa_juridica.js b/pessoa_juridica.js new file mode 100644 index 0000000..0ce1f15 --- /dev/null +++ b/pessoa_juridica.js @@ -0,0 +1,23 @@ +import Pessoa from './pessoa.js' + +class PessoaJuridica extends Pessoa { + #_cnpj + + constructor(nome) { + super(nome) + } + + set cnpj(cnpj) { + this.#_cnpj = cnpj + } + + get cnpj() { + return this.#_cnpj + } + + mostrarDados(){ + return `Meus dados são: ${this.nome} e ${this.cnpj}` + } +} + +export default PessoaJuridica \ No newline at end of file