├── Entity.java ├── LICENSE ├── README.md ├── Value Object 1.java └── Value Object 2.java /Entity.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class ListaAlunos { 4 | private ArrayList listaAlunos = new ArrayList<>(); 5 | 6 | private int geraMatricula() { 7 | return listaAlunos.size(); 8 | } 9 | 10 | public void setAluno(String DadosAluno) { 11 | listaAlunos.add(geraMatricula() + ", " + DadosAluno); 12 | System.out.println("Registro: " + geraMatricula() + ", " + DadosAluno); 13 | System.out.println("Inserido!"); 14 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 15 | } 16 | } 17 | 18 | class NomeCompleto { 19 | private String primeiro_nome; 20 | private String nome_do_meio; 21 | private String ultimo_nome; 22 | 23 | public String nome_completo(String primeiro_nome, String nome_do_meio, String ultimo_nome) { 24 | String nome_completo; 25 | this.primeiro_nome = primeiro_nome.toLowerCase(); 26 | this.nome_do_meio = nome_do_meio.toLowerCase(); 27 | this.ultimo_nome = ultimo_nome.toLowerCase(); 28 | 29 | this.primeiro_nome = this.primeiro_nome.substring(0, 1).toUpperCase() + this.primeiro_nome.substring(1); 30 | this.nome_do_meio = this.nome_do_meio.substring(0, 1).toUpperCase() + this.nome_do_meio.substring(1); 31 | this.ultimo_nome = this.ultimo_nome.substring(0, 1).toUpperCase() + this.ultimo_nome.substring(1); 32 | 33 | nome_completo = this.primeiro_nome + " " + this.nome_do_meio + " " + this.ultimo_nome; 34 | 35 | return nome_completo; 36 | } 37 | } 38 | 39 | class DataNascimento { 40 | private String dia_nascimento; 41 | private String mes_nascimento; 42 | private String ano_nascimento; 43 | 44 | public String data_nascimento(String dia_nascimento, String mes_nascimento, String ano_nascimento) { 45 | String nascimento_completo = ""; 46 | this.dia_nascimento = dia_nascimento; 47 | this.mes_nascimento = mes_nascimento; 48 | this.ano_nascimento = ano_nascimento; 49 | 50 | // Testando se há alguma data vazia 51 | if(this.dia_nascimento.length() == 0 || this.mes_nascimento.length() == 0 || ano_nascimento.length() == 0 || ano_nascimento.length() < 4) { 52 | nascimento_completo = "Erro: Data Inválida!"; 53 | } 54 | 55 | // Complementa a data se houver apenas um número 56 | if(this.dia_nascimento.length() == 1) { 57 | this.dia_nascimento = "0" + this.dia_nascimento; 58 | } 59 | 60 | // Complementa a data se houver apenas um número 61 | if(this.mes_nascimento.length() == 1) { 62 | this.mes_nascimento = "0" + this.mes_nascimento; 63 | } 64 | 65 | nascimento_completo = this.dia_nascimento + "/" + this.mes_nascimento + "/" + this.ano_nascimento; 66 | 67 | return nascimento_completo; 68 | } 69 | } 70 | 71 | class EnderecoCompleto { 72 | private String rua; 73 | private String numero; 74 | private String complemento; 75 | private String cep; 76 | private String cidade; 77 | private String estado; 78 | private String pais; 79 | 80 | public String endereco_completo(String rua, String numero, String complemento, String cep, String cidade, String estado, String pais) { 81 | String endereco_completo = ""; 82 | this.rua = rua; 83 | this.numero = numero; 84 | this.complemento = complemento; 85 | this.cep = cep; 86 | this.cidade = cidade; 87 | this.estado = estado; 88 | this.pais = pais; 89 | 90 | // Forçando que tudo seja minúsculo 91 | this.rua = this.rua.toLowerCase(); 92 | this.cidade = this.cidade.toLowerCase(); 93 | this.estado = this.estado.toLowerCase(); 94 | this.pais = this.pais.toLowerCase(); 95 | 96 | // Capitalizando somente a primeira letra 97 | this.rua = this.rua.substring(0, 1).toUpperCase() + this.rua.substring(1); 98 | this.cidade = this.cidade.substring(0, 1).toUpperCase() + this.cidade.substring(1);; 99 | this.estado = this.estado.substring(0, 1).toUpperCase() + this.estado.substring(1); 100 | this.pais = this.pais.substring(0, 1).toUpperCase() + this.pais.substring(1); 101 | 102 | endereco_completo = this.rua + ", " + this.numero + ", " + this.complemento + ", " + this.cep + ", " + this.cidade + " - " + this.estado + " - " + this.pais; 103 | 104 | return endereco_completo; 105 | } 106 | } 107 | 108 | // Classe Aluno Value Object 2 109 | class Aluno_va2 { 110 | 111 | ListaAlunos lista_alunos = new ListaAlunos(); 112 | 113 | public void setAluno (String primeiro_nome, String nome_do_meio, String ultimo_nome, String dia_nascimento, String mes_nascimento, String ano_nascimento, String rua, String numero, String complemento, String cep, String cidade, String estado, String pais) { 114 | NomeCompleto nome_completo = new NomeCompleto(); 115 | DataNascimento data_nascimento = new DataNascimento(); 116 | EnderecoCompleto endereco_completo = new EnderecoCompleto(); 117 | 118 | String dados_aluno = nome_completo.nome_completo(primeiro_nome, nome_do_meio, ultimo_nome) + ", " + data_nascimento.data_nascimento(dia_nascimento, mes_nascimento, ano_nascimento) + ", " + endereco_completo.endereco_completo(rua, numero, complemento, cep, cidade, estado, pais); 119 | 120 | lista_alunos.setAluno(dados_aluno); 121 | } 122 | 123 | public static void main(String[] Args) { 124 | Aluno_va2 novo_aluno = new Aluno_va2(); 125 | 126 | // Primeira Entrada 127 | novo_aluno.setAluno("Vlad", "Tepes", "Dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 128 | 129 | // Segunda Entrada 130 | novo_aluno.setAluno("vLad", "Tepes", "DracuL", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 131 | 132 | // Terceira Entrada 133 | novo_aluno.setAluno("vlad", "tepes", "dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 134 | 135 | // Quarta Entrada 136 | novo_aluno.setAluno("conde", "don", "dracula", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 137 | } 138 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 FIAP - Faculdade de Informática e Administração Paulista 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DDD 2 | Materiais sobre Domain-Driven Design 3 | -------------------------------------------------------------------------------- /Value Object 1.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class ListaAlunos { 4 | private ArrayList listaAlunos = new ArrayList<>(); 5 | 6 | public void setAluno(String DadosAluno) { 7 | int list_size = listaAlunos.size(); 8 | 9 | if(listaAlunos.isEmpty()) { 10 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 11 | listaAlunos.add(DadosAluno); 12 | System.out.println("Registro: " + DadosAluno); 13 | System.out.println("Inserido!"); 14 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 15 | } 16 | else { 17 | for(int i = 0; i < list_size; i++) { 18 | if(listaAlunos.get(i).equals(DadosAluno)) { 19 | System.out.println("Registro: " + DadosAluno); 20 | System.out.println("Já Existe!"); 21 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 22 | } 23 | else { 24 | listaAlunos.add(DadosAluno); 25 | System.out.println("Registro: " + DadosAluno); 26 | System.out.println("Inserido!"); 27 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 28 | } 29 | } 30 | } 31 | 32 | } 33 | } 34 | 35 | // Classe Aluno Value Object 1 36 | class Aluno_va1 { 37 | private String primeiro_nome; 38 | private String nome_do_meio; 39 | private String ultimo_nome; 40 | private String dia_nascimento; 41 | private String mes_nascimento; 42 | private String ano_nascimento; 43 | private String rua; 44 | private String numero; 45 | private String complemento; 46 | private String cep; 47 | private String cidade; 48 | private String estado; 49 | private String pais; 50 | 51 | ListaAlunos lista_alunos = new ListaAlunos(); 52 | 53 | private String NomeCompleto() { 54 | String nome_completo; 55 | // Forçando que tudo seja minúsculo 56 | this.primeiro_nome = this.primeiro_nome.toLowerCase(); 57 | this.nome_do_meio = this.nome_do_meio.toLowerCase(); 58 | this.ultimo_nome = this.ultimo_nome.toLowerCase(); 59 | 60 | // Capitalizando somente a primeira letra 61 | this.primeiro_nome = this.primeiro_nome.substring(0, 1).toUpperCase() + this.primeiro_nome.substring(1); 62 | this.nome_do_meio = this.nome_do_meio.substring(0, 1).toUpperCase() + this.nome_do_meio.substring(1); 63 | this.ultimo_nome = this.ultimo_nome.substring(0, 1).toUpperCase() + this.ultimo_nome.substring(1); 64 | 65 | nome_completo = this.primeiro_nome + " " + this.nome_do_meio + " " + this.ultimo_nome; 66 | 67 | return nome_completo; 68 | } 69 | 70 | private String DataNascimento() { 71 | String nascimento_completo; 72 | nascimento_completo = ""; 73 | 74 | // Testando se há alguma data vazia 75 | if(this.dia_nascimento.length() == 0 || this.mes_nascimento.length() == 0 || ano_nascimento.length() == 0 || ano_nascimento.length() < 4) { 76 | nascimento_completo = "Erro: Data Inválida!"; 77 | } 78 | 79 | // Complementa a data se houver apenas um número 80 | if(this.dia_nascimento.length() == 1) { 81 | this.dia_nascimento = "0" + this.dia_nascimento; 82 | } 83 | 84 | // Complementa a data se houver apenas um número 85 | if(this.mes_nascimento.length() == 1) { 86 | this.mes_nascimento = "0" + this.mes_nascimento; 87 | } 88 | 89 | nascimento_completo = this.dia_nascimento + "/" + this.mes_nascimento + "/" + this.ano_nascimento; 90 | 91 | return nascimento_completo; 92 | } 93 | 94 | private String EnderecoCompleto() { 95 | String endereco_completo; 96 | 97 | // Forçando que tudo seja minúsculo 98 | this.rua = this.rua.toLowerCase(); 99 | this.cidade = this.cidade.toLowerCase(); 100 | this.estado = this.estado.toLowerCase(); 101 | this.pais = this.pais.toLowerCase(); 102 | 103 | // Capitalizando somente a primeira letra 104 | this.rua = this.rua.substring(0, 1).toUpperCase() + this.rua.substring(1); 105 | this.cidade = this.cidade.substring(0, 1).toUpperCase() + this.cidade.substring(1);; 106 | this.estado = this.estado.substring(0, 1).toUpperCase() + this.estado.substring(1); 107 | this.pais = this.pais.substring(0, 1).toUpperCase() + this.pais.substring(1); 108 | 109 | endereco_completo = this.rua + ", " + this.numero + ", " + this.complemento + ", " + this.cep + ", " + this.cidade + " - " + this.estado + " - " + this.pais; 110 | 111 | return endereco_completo; 112 | } 113 | 114 | public void setAluno(String primeiro_nome, String nome_do_meio, String ultimo_nome, String dia_nascimento, String mes_nascimento, String ano_nascimento, String rua, String numero, String complemento, String cep, String cidade, String estado, String pais) { 115 | this.primeiro_nome = primeiro_nome; 116 | this.nome_do_meio = nome_do_meio; 117 | this.ultimo_nome = ultimo_nome; 118 | this.dia_nascimento = dia_nascimento; 119 | this.mes_nascimento = mes_nascimento; 120 | this.ano_nascimento = ano_nascimento; 121 | this.rua = rua; 122 | this.numero = numero; 123 | this.complemento = complemento; 124 | this.cep = cep; 125 | this.cidade = cidade; 126 | this.estado = estado; 127 | this.pais = pais; 128 | 129 | String dados_aluno = NomeCompleto() + ", " + DataNascimento() + ", " + EnderecoCompleto(); 130 | lista_alunos.setAluno(dados_aluno); 131 | } 132 | 133 | public static void main(String[] Args) { 134 | Aluno_va1 novo_aluno = new Aluno_va1(); 135 | 136 | // Primeira Entrada 137 | novo_aluno.setAluno("Vlad", "Tepes", "Dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 138 | 139 | // Segunda Entrada 140 | novo_aluno.setAluno("vLad", "Tepes", "DracuL", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 141 | 142 | // Terceira Entrada 143 | novo_aluno.setAluno("vlad", "tepes", "dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 144 | 145 | // Quarta Entrada 146 | novo_aluno.setAluno("conde", "don", "dracula", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 147 | } 148 | } -------------------------------------------------------------------------------- /Value Object 2.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class ListaAlunos { 4 | private ArrayList listaAlunos = new ArrayList<>(); 5 | 6 | public void setAluno(String DadosAluno) { 7 | int list_size = listaAlunos.size(); 8 | 9 | if(listaAlunos.isEmpty()) { 10 | System.out.println(" Tamanho da Lista: " + listaAlunos.size()); 11 | listaAlunos.add(DadosAluno); 12 | System.out.println("Registro: " + DadosAluno); 13 | System.out.println("Inserido!"); 14 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 15 | } 16 | else { 17 | for(int i = 0; i < list_size; i++) { 18 | if(listaAlunos.get(i).equals(DadosAluno)) { 19 | System.out.println("Registro: " + DadosAluno); 20 | System.out.println("Já Existe!"); 21 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 22 | } 23 | else { 24 | listaAlunos.add(DadosAluno); 25 | System.out.println("Registro: " + DadosAluno); 26 | System.out.println("Inserido!"); 27 | System.out.println("Tamanho da Lista: " + listaAlunos.size()); 28 | } 29 | } 30 | } 31 | 32 | } 33 | } 34 | 35 | class NomeCompleto { 36 | private String primeiro_nome; 37 | private String nome_do_meio; 38 | private String ultimo_nome; 39 | 40 | public String nome_completo(String primeiro_nome, String nome_do_meio, String ultimo_nome) { 41 | String nome_completo; 42 | this.primeiro_nome = primeiro_nome.toLowerCase(); 43 | this.nome_do_meio = nome_do_meio.toLowerCase(); 44 | this.ultimo_nome = ultimo_nome.toLowerCase(); 45 | 46 | this.primeiro_nome = this.primeiro_nome.substring(0, 1).toUpperCase() + this.primeiro_nome.substring(1); 47 | this.nome_do_meio = this.nome_do_meio.substring(0, 1).toUpperCase() + this.nome_do_meio.substring(1); 48 | this.ultimo_nome = this.ultimo_nome.substring(0, 1).toUpperCase() + this.ultimo_nome.substring(1); 49 | 50 | nome_completo = this.primeiro_nome + " " + this.nome_do_meio + " " + this.ultimo_nome; 51 | 52 | return nome_completo; 53 | } 54 | } 55 | 56 | class DataNascimento { 57 | private String dia_nascimento; 58 | private String mes_nascimento; 59 | private String ano_nascimento; 60 | 61 | public String data_nascimento(String dia_nascimento, String mes_nascimento, String ano_nascimento) { 62 | String nascimento_completo = ""; 63 | this.dia_nascimento = dia_nascimento; 64 | this.mes_nascimento = mes_nascimento; 65 | this.ano_nascimento = ano_nascimento; 66 | 67 | // Testando se há alguma data vazia 68 | if(this.dia_nascimento.length() == 0 || this.mes_nascimento.length() == 0 || ano_nascimento.length() == 0 || ano_nascimento.length() < 4) { 69 | nascimento_completo = "Erro: Data Inválida!"; 70 | } 71 | 72 | // Complementa a data se houver apenas um número 73 | if(this.dia_nascimento.length() == 1) { 74 | this.dia_nascimento = "0" + this.dia_nascimento; 75 | } 76 | 77 | // Complementa a data se houver apenas um número 78 | if(this.mes_nascimento.length() == 1) { 79 | this.mes_nascimento = "0" + this.mes_nascimento; 80 | } 81 | 82 | nascimento_completo = this.dia_nascimento + "/" + this.mes_nascimento + "/" + this.ano_nascimento; 83 | 84 | return nascimento_completo; 85 | } 86 | } 87 | 88 | class EnderecoCompleto { 89 | private String rua; 90 | private String numero; 91 | private String complemento; 92 | private String cep; 93 | private String cidade; 94 | private String estado; 95 | private String pais; 96 | 97 | public String endereco_completo(String rua, String numero, String complemento, String cep, String cidade, String estado, String pais) { 98 | String endereco_completo = ""; 99 | this.rua = rua; 100 | this.numero = numero; 101 | this.complemento = complemento; 102 | this.cep = cep; 103 | this.cidade = cidade; 104 | this.estado = estado; 105 | this.pais = pais; 106 | 107 | // Forçando que tudo seja minúsculo 108 | this.rua = this.rua.toLowerCase(); 109 | this.cidade = this.cidade.toLowerCase(); 110 | this.estado = this.estado.toLowerCase(); 111 | this.pais = this.pais.toLowerCase(); 112 | 113 | // Capitalizando somente a primeira letra 114 | this.rua = this.rua.substring(0, 1).toUpperCase() + this.rua.substring(1); 115 | this.cidade = this.cidade.substring(0, 1).toUpperCase() + this.cidade.substring(1);; 116 | this.estado = this.estado.substring(0, 1).toUpperCase() + this.estado.substring(1); 117 | this.pais = this.pais.substring(0, 1).toUpperCase() + this.pais.substring(1); 118 | 119 | endereco_completo = this.rua + ", " + this.numero + ", " + this.complemento + ", " + this.cep + ", " + this.cidade + " - " + this.estado + " - " + this.pais; 120 | 121 | return endereco_completo; 122 | } 123 | } 124 | 125 | // Classe Aluno Value Object 2 126 | class Aluno_va2 { 127 | 128 | ListaAlunos lista_alunos = new ListaAlunos(); 129 | 130 | public void setAluno (String primeiro_nome, String nome_do_meio, String ultimo_nome, String dia_nascimento, String mes_nascimento, String ano_nascimento, String rua, String numero, String complemento, String cep, String cidade, String estado, String pais) { 131 | NomeCompleto nome_completo = new NomeCompleto(); 132 | DataNascimento data_nascimento = new DataNascimento(); 133 | EnderecoCompleto endereco_completo = new EnderecoCompleto(); 134 | 135 | String dados_aluno = nome_completo.nome_completo(primeiro_nome, nome_do_meio, ultimo_nome) + ", " + data_nascimento.data_nascimento(dia_nascimento, mes_nascimento, ano_nascimento) + ", " + endereco_completo.endereco_completo(rua, numero, complemento, cep, cidade, estado, pais); 136 | 137 | lista_alunos.setAluno(dados_aluno); 138 | } 139 | 140 | public static void main(String[] Args) { 141 | Aluno_va2 novo_aluno = new Aluno_va2(); 142 | 143 | // Primeira Entrada 144 | novo_aluno.setAluno("Vlad", "Tepes", "Dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 145 | 146 | // Segunda Entrada 147 | novo_aluno.setAluno("vLad", "Tepes", "DracuL", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 148 | 149 | // Terceira Entrada 150 | novo_aluno.setAluno("vlad", "tepes", "dracul", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 151 | 152 | // Quarta Entrada 153 | novo_aluno.setAluno("conde", "don", "dracula", "7", "12", "1431", "Piata Cetatii", "8", "", "545400", "Sighisoara", "Transilvânia", "Romenia"); 154 | } 155 | } --------------------------------------------------------------------------------