├── Codigo ├── 00_Java_Revisao_e_Nivelamento │ ├── 03_CalculadoraCLI │ │ ├── dados.txt │ │ ├── resultados.txt │ │ ├── .vscode │ │ │ └── settings.json │ │ ├── README.md │ │ └── src │ │ │ ├── Calculadora.java │ │ │ └── CalculadoraArquivos.java │ ├── 00_ES_e_Decisao │ │ ├── src │ │ │ ├── HelloWorld.java │ │ │ ├── HelloStudent.java │ │ │ └── MaiorDeTres.java │ │ ├── .vscode │ │ │ └── settings.json │ │ └── README.md │ ├── 01_InverterVetor │ │ ├── .vscode │ │ │ └── settings.json │ │ ├── README.md │ │ └── src │ │ │ └── InverterVetor.java │ └── 02_MediaValores │ │ ├── .vscode │ │ └── settings.json │ │ ├── README.md │ │ └── src │ │ └── MediaVetor.java └── 01_POO_Basica │ ├── 00_Produto_Basico │ ├── .vscode │ │ └── settings.json │ ├── README.md │ └── src │ │ ├── MainProduto.java │ │ └── Produto.java │ └── 00a_Pratica_Produto_Sistema │ ├── .vscode │ └── settings.json │ ├── README.md │ └── src │ ├── Principal.java │ ├── Produto.java │ └── XulambsConveniencias.java ├── README.md ├── .gitignore └── LICENSE /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/dados.txt: -------------------------------------------------------------------------------- 1 | 23 + 19 2 | 4,7 * 8,93 3 | 5,9 / 9,25 4 | 31 - 16 5 | FIM -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/resultados.txt: -------------------------------------------------------------------------------- 1 | 23 + 19 = 42.0 2 | 4,7 * 8,93 = 41.971000000000004 3 | 5,9 / 9,25 = 0.6378378378378379 4 | 31 - 16 = 15.0 5 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/00_ES_e_Decisao/src/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | public static void main(String[] args) throws Exception { 3 | System.out.println("Hello, World!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00_Produto_Basico/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00a_Pratica_Produto_Sistema/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/00_ES_e_Decisao/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/01_InverterVetor/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/02_MediaValores/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": ["src"], 3 | "java.project.outputPath": "bin", 4 | "java.project.referencedLibraries": [ 5 | "lib/**/*.jar" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laboratório de Programação Modular - LPM 2 | 3 | ## Semestre 2/2024 4 | 5 | Repositório de conteúdo da disciplina Laboratório de Programação Modular, (Bacharelado em Engenharia de Software, PUC Minas Praça da Liberdade). Ênfase nos códigos utilizados na disciplina e guias de solução de exemplos/exercícios. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/00_ES_e_Decisao/src/HelloStudent.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class HelloStudent { 4 | public static void main(String[] args) { 5 | Scanner leitor = new Scanner(System.in); 6 | String nome; 7 | 8 | System.out.print("Qual o seu nome, padawan? "); 9 | nome = leitor.nextLine(); 10 | 11 | System.out.println("Que a força do Java esteja com você, "+nome); 12 | System.out.printf("Que a força do Java esteja com você, %s", nome); 13 | 14 | leitor.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00_Produto_Basico/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00a_Pratica_Produto_Sistema/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/00_ES_e_Decisao/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/01_InverterVetor/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/02_MediaValores/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/README.md: -------------------------------------------------------------------------------- 1 | ## Getting Started 2 | 3 | Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code. 4 | 5 | ## Folder Structure 6 | 7 | The workspace contains two folders by default, where: 8 | 9 | - `src`: the folder to maintain sources 10 | - `lib`: the folder to maintain dependencies 11 | 12 | Meanwhile, the compiled output files will be generated in the `bin` folder by default. 13 | 14 | > If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there. 15 | 16 | ## Dependency Management 17 | 18 | The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies). 19 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/00_ES_e_Decisao/src/MaiorDeTres.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MaiorDeTres { 4 | 5 | public static double maiorDeTres(double num1, double num2, double num3){ 6 | double maior = num1; 7 | 8 | if(num2 > maior ){ 9 | maior = num2; 10 | } 11 | 12 | if(num3 > maior){ 13 | maior = num3; 14 | } 15 | 16 | return maior; 17 | } 18 | 19 | public static void main(String[] args) { 20 | double num1, num2, num3; 21 | Scanner teclado = new Scanner(System.in); 22 | 23 | System.out.print("Digite três números separados por espaço: "); 24 | num1 = teclado.nextDouble(); 25 | num2 = teclado.nextDouble(); 26 | num3 = teclado.nextDouble(); 27 | 28 | System.out.printf("O maior dos três é %f.", maiorDeTres(num1, num2, num3)); 29 | teclado.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-24 Joao Caram 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 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/02_MediaValores/src/MediaVetor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class MediaVetor { 4 | 5 | public static double[] criarVetor(Scanner teclado){ 6 | int tamanhoVetor; 7 | 8 | System.out.print("Qual o tamanho do vetor a ser lido? "); 9 | 10 | tamanhoVetor = Integer.parseInt(teclado.nextLine()); 11 | return new double[tamanhoVetor]; 12 | } 13 | 14 | public static void lerVetor(double[] vetor, Scanner teclado){ 15 | for (int i = 0; i < vetor.length; i++){ 16 | System.out.print("Digite o valor " + (i + 1) + ": "); 17 | vetor[i] = Double.parseDouble(teclado.nextLine()); 18 | } 19 | 20 | } 21 | 22 | public static double somarVetor(double[] vetor){ 23 | double soma = 0d; 24 | for (int i = 0; i < vetor.length; i++) { 25 | soma += vetor[i]; 26 | } 27 | return soma; 28 | } 29 | 30 | public static double mediaValores(double[] vetor){ 31 | return somarVetor(vetor) / vetor.length; 32 | } 33 | 34 | 35 | public static void main(String[] args) throws Exception { 36 | Scanner teclado; 37 | double[] vetor; 38 | 39 | teclado = new Scanner(System.in); 40 | vetor = criarVetor(teclado); 41 | System.out.println(); 42 | lerVetor(vetor, teclado); 43 | System.out.println("O vetor tem "+vetor.length+" elementos. A soma dos elementos é "+somarVetor(vetor)); 44 | System.out.println("A média dos valores do vetor é de " + String.format("%.2f", mediaValores(vetor))); 45 | 46 | teclado.close(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00a_Pratica_Produto_Sistema/src/Principal.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright(c) 2022-24 João Caram 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** "Teste" em um main que exibe dados em console. Ainda aprenderemos a fazer testes melhores... */ 26 | public class Principal { 27 | 28 | public static void main(String[] args) { 29 | Produto meuProduto = new Produto(); 30 | double precoLote = 0d; 31 | meuProduto.registrar("Chá mate com gás", 2); 32 | System.out.println(meuProduto.descricao); 33 | System.out.println(meuProduto.valorUnitario); 34 | 35 | precoLote = meuProduto.valorLote(-4); 36 | System.out.println(precoLote); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00_Produto_Basico/src/MainProduto.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright(c) 2024 João Caram 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | /** 28 | * App-demo simples para iniciação aos conceitos de POO. 29 | */ 30 | public class MainProduto { 31 | 32 | public static void main(String[] args) { 33 | Scanner teclado = new Scanner(System.in); 34 | Produto chaComGas = new Produto("Chá mate com gás", 3.49); 35 | int quantidade; 36 | 37 | System.out.println("Uma lata de chá com gás está custando R$ "+chaComGas.precoUnitario); //por que isso não está bom? 38 | System.out.print("Quer comprar quantas latas? "); 39 | quantidade = Integer.parseInt(teclado.nextLine()); 40 | System.out.println(quantidade + " latas de chá com gás custam R$ "+ chaComGas.valorDoLote(quantidade)); 41 | 42 | teclado.close(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00_Produto_Basico/src/Produto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright(c) 2024 João Caram 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | /** 27 | * Classe (MUITO) simples "Produto" para iniciação aos conceitos de POO. 28 | * Aqui ainda não temos preocupação com os aspectos de modularidade, que serão trabalhadas mais à frente na disciplina. 29 | */ 30 | public class Produto { 31 | public String descricao; //para pensar: será boa ideia deixar estes valores como públicos? 32 | public double precoUnitario; //para pensar: double é valor financeiro? podemos usar BigDecimal? Currency? 33 | 34 | /** 35 | * Construtor do produto: aceita qualquer descrição, inclusive vazia. O preço mínimo é R$1 (corrigido pelo construtor se necessário) 36 | * @param desc Descrição do produto (string sem limite de tamanho) 37 | * @param preco Preço unitário do produto (>=1.0) 38 | */ 39 | public Produto(String desc, double preco){ 40 | this.precoUnitario = 1d; 41 | if(preco>1d) 42 | this.precoUnitario = preco; 43 | this.descricao = desc; 44 | } 45 | 46 | /** 47 | * Informa o preço de venda de um lote do produto, com a quantidade rebecida/informada por parâmetro. Se a quantidade for inválida (isto é, não-positiva) retorna 0.0. 48 | * @param quantidade A quantidade de produtos do lote a ser vendido. 49 | * @return O valor do lote de produtos. Retorna 0.0 em caso de tamanho inválido de lote (<1). 50 | */ 51 | public double valorDoLote(int quantidade){ 52 | double valor = 0d; 53 | if(quantidade >=1 ) 54 | valor = precoUnitario * quantidade; 55 | return valor; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00a_Pratica_Produto_Sistema/src/Produto.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MIT License 3 | * 4 | * Copyright(c) 2022-24 João Caram 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** Classe Produto para demonstração básica dos conceitos de POO. Pode (e vai) ser muito melhorada */ 26 | public class Produto { 27 | 28 | //#region atributos 29 | String descricao; 30 | double valorUnitario; 31 | //#endregion 32 | 33 | //#region métodos 34 | /** 35 | * Registra os dados de um produto. Descrição e valor (acima de 0). 36 | * Valores inválidos serão registrados como R$0,10. 37 | * @param desc String com o nome do produto. Strings vazias resultarão em "Produto sem descrição" 38 | * @param valor Valor unitário do produto. Deve ser maior que 0. 39 | */ 40 | void registrar(String desc, double valor){ 41 | if(desc.length()==0) 42 | desc = "Produto sem descrição"; 43 | if(valor<=0) 44 | valor = 0.1; 45 | descricao = desc; 46 | valorUnitario = valor; 47 | } 48 | 49 | /** 50 | * Retorna o valor de venda de um lote de QUANT produtos. 51 | * Quant deve ser maior que 0, ou será considerada a venda de uma unidade. 52 | * @param quant O tamanho do lote (maior que 0). Valores inválidos serão 53 | * considerados como lotes de 1 unidade. 54 | * @return Valor do lote para QUANT produtos. 55 | */ 56 | double valorLote(int quant){ 57 | if(quant < 1) 58 | quant = 1; 59 | return valorUnitario * quant; 60 | } 61 | 62 | 63 | /** 64 | * Retorna a descrição de um produto, com seu valor unitário. 65 | * @return Uma string no formato "DESCRICAO: R" 66 | */ 67 | String descricaoProduto(){ 68 | return String.format("%s: R$ %.2f", descricao, valorUnitario); 69 | } 70 | 71 | //#endregion 72 | } 73 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/src/Calculadora.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright(c) 2022-24 João Caram 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | public class Calculadora { 27 | static Scanner leitorTeclado; 28 | 29 | private static String lerCalculo() { 30 | System.out.println("Digite a expressão no formato ou 'FIM' para terminar"); 31 | return leitorTeclado.nextLine(); 32 | } 33 | 34 | private static double interpretarCalculo(String calculo){ 35 | String[] componentes; 36 | double resultado; 37 | 38 | componentes = calculo.split(" "); 39 | if(componentes.length != 3){ 40 | resultado = 0d; 41 | } 42 | else{ 43 | componentes[0] = componentes[0].replace(',', '.'); 44 | componentes[2] = componentes[2].replace(',', '.'); 45 | double valor1 = Double.parseDouble(componentes[0]); 46 | double valor2 = Double.parseDouble(componentes[2]); 47 | switch (componentes[1]) { 48 | case "+" -> resultado = valor1+valor2; 49 | case "-" -> resultado = valor1-valor2; 50 | case "/" -> resultado = valor1/valor2; 51 | case "*" -> resultado = valor1*valor2; 52 | default -> resultado = 0d; 53 | } 54 | } 55 | return resultado; 56 | } 57 | 58 | public static void main(String[] args) throws Exception { 59 | leitorTeclado = new Scanner(System.in); 60 | String calculo; 61 | double resultado; 62 | 63 | calculo = lerCalculo(); 64 | while (!calculo.equals("FIM")) { 65 | resultado = interpretarCalculo(calculo); 66 | System.out.println(calculo + " = "+ resultado); 67 | calculo = lerCalculo(); 68 | } 69 | 70 | leitorTeclado.close(); 71 | } 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/03_CalculadoraCLI/src/CalculadoraArquivos.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileWriter; 3 | import java.util.Scanner; 4 | 5 | /** 6 | * MIT License 7 | * 8 | * Copyright(c) 2022-24 João Caram 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | public class CalculadoraArquivos { 29 | static Scanner leitorTeclado; 30 | static Scanner leitorArquivo; 31 | 32 | 33 | 34 | private static double interpretarCalculo(String calculo){ 35 | String[] componentes; 36 | double resultado; 37 | 38 | componentes = calculo.split(" "); 39 | if(componentes.length != 3){ 40 | resultado = 0d; 41 | } 42 | else{ 43 | componentes[0] = componentes[0].replace(',', '.'); 44 | componentes[2] = componentes[2].replace(',', '.'); 45 | double valor1 = Double.parseDouble(componentes[0]); 46 | double valor2 = Double.parseDouble(componentes[2]); 47 | switch (componentes[1]) { 48 | case "+" -> resultado = valor1+valor2; 49 | case "-" -> resultado = valor1-valor2; 50 | case "/" -> resultado = valor1/valor2; 51 | case "*" -> resultado = valor1*valor2; 52 | default -> resultado = 0d; 53 | } 54 | } 55 | return resultado; 56 | } 57 | 58 | public static void main(String[] args) throws Exception { 59 | leitorTeclado = new Scanner(System.in); 60 | FileWriter arqResultados = new FileWriter("resultados.txt"); 61 | 62 | String calculo; 63 | String nomeArquivo; 64 | double resultado; 65 | 66 | System.out.print("Qual é o arquivo com as contas? "); 67 | nomeArquivo = leitorTeclado.nextLine(); 68 | 69 | leitorArquivo = new Scanner(new File(nomeArquivo)); 70 | 71 | while (leitorArquivo.hasNextLine()) { 72 | calculo = leitorArquivo.nextLine(); 73 | if(!calculo.equals("FIM")){ 74 | resultado = interpretarCalculo(calculo); 75 | System.out.println(calculo + " = "+ resultado); 76 | arqResultados.write(calculo + " = "+ resultado+"\n"); 77 | } 78 | } 79 | arqResultados.close(); 80 | leitorArquivo.close(); 81 | leitorTeclado.close(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Codigo/01_POO_Basica/00a_Pratica_Produto_Sistema/src/XulambsConveniencias.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | /** 5 | * MIT License 6 | * 7 | * Copyright(c) 2022-24 João Caram 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in all 17 | * copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | */ 27 | 28 | /** Sistema de Vendas para a Xulambs Conveniências. */ 29 | public class XulambsConveniencias { 30 | static Scanner teclado = new Scanner(System.in); 31 | 32 | /** 33 | * Encapsula uma pausa (leitura de teclado) no aplicativo de console. 34 | */ 35 | public static void pausa(){ 36 | System.out.print("Pressione para continuar."); 37 | teclado.nextLine(); 38 | } 39 | 40 | /** 41 | * Loop para cadastrar produtos a partir do teclado e retorná-los em um array. Podem ser cadastrados até 100 produtos. 42 | * A tentativa de ler mais do que 100 produtos causará um erro. 43 | * @return Um array com os produtos (pode estar vazio). 44 | */ 45 | public static Produto[] cadastrarProdutos(){ 46 | final int MAX_PRODUTOS = 100; 47 | Produto[] novosProdutos = new Produto[MAX_PRODUTOS]; 48 | Produto novo; 49 | int quantosProdutos = 0; 50 | String descricao; 51 | double valorUnitario; 52 | String continuar = "s"; 53 | do{ 54 | System.out.println("CADASTRO DE PRODUTO"); 55 | System.out.print("Descrição do produto: "); 56 | descricao = teclado.nextLine(); 57 | System.out.print("Valor unitário do produto: "); 58 | valorUnitario = Double.parseDouble(teclado.nextLine()); 59 | novo = new Produto(); 60 | novo.registrar(descricao, valorUnitario); 61 | novosProdutos[quantosProdutos] = novo; 62 | quantosProdutos++; 63 | System.out.println(); 64 | System.out.print("Continuar cadastro (s/n)?"); 65 | continuar = teclado.nextLine(); 66 | }while(continuar.toLowerCase().equals("s")); 67 | novosProdutos = Arrays.copyOf(novosProdutos, quantosProdutos); 68 | return novosProdutos; 69 | } 70 | 71 | /** 72 | * Encapsula o processo de adicionar um produto na venda: recebe a quantidade vendida, 73 | * calcula o valor total a ser adicionado na venda e retorna este valor. Como o valor do lote do produto é protegido, 74 | * a quantidade mínima de venda é de 1 unidade. 75 | * @param prod O produto a ser vendido. 76 | * @return O valor obtido com a venda de N unidades deste produto (N sendo definido pela pessoa operadora na execução) 77 | */ 78 | public static double adicionarNaVenda(Produto prod){ 79 | //TODO: código do método 80 | return 0d; 81 | } 82 | 83 | public static void main(String[] args) { 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Codigo/00_Java_Revisao_e_Nivelamento/01_InverterVetor/src/InverterVetor.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * MIT License 5 | * 6 | * Copyright(c) 2022-24 João Caram 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | */ 26 | 27 | public class InverterVetor{ 28 | static Scanner leitor = new Scanner(System.in); //objeto para leitura de teclado (entrada padrão do Sistema) 29 | 30 | /** 31 | * Inverte um vetor de inteiros, modificando o próprio vetor (método 'in-place') 32 | * @param vetor O vetor de inteiros a ser invertido. Este vetor será modificado pelo método, estando invertido em relação ao original no final da execução. 33 | */ 34 | static void inverterVetor(int vetor[]) { 35 | int tmp; 36 | int oposto; 37 | int tamanho = vetor.length; 38 | for (int i = 0; i < (tamanho/2); i++) { 39 | oposto = (tamanho - i - 1); 40 | tmp = vetor[i]; 41 | vetor[i] = vetor[oposto]; 42 | vetor[oposto] = tmp; 43 | } 44 | } 45 | 46 | /** 47 | * Cria e lê do teclado um vetor do tamanho escolhido pelo usuário. O tamanho deve ser passado por parâmetro. Em caso de tamanho não positivo, o método retorna um vetor vazio de tamanho 2. 48 | * ATENÇÃO: método 'acoplado' ao Console como objeto de saída e teclado como entrada (pode ser melhorado). 49 | * @param tamanho O tamanho do vetor a ser criado e lido. Deve ser um valor positivo (>=1). 50 | * @return Um vetor com o tamanho definido e valores lidos a partir do teclado ou um vetor vazio de tamanho 2, caso o tamanho informado seja inválido. 51 | * @throws NumberFormatException Causa um erro de formato caso o valor lido do teclado para o vetor não seja numérico. 52 | */ 53 | static int[] lerVetor(int tamanho){ 54 | int[] vetor = new int[2]; 55 | if(tamanho>=1){ 56 | vetor = new int[tamanho]; 57 | for (int i = 0; i < tamanho; i++) { 58 | System.out.print("Digite o número na posição "+ (i + 1) +": "); 59 | vetor[i] = Integer.parseInt(leitor.nextLine()); 60 | } 61 | } 62 | return vetor; 63 | } 64 | 65 | /** 66 | * Imprime um vetor passado como parâmetro. A impressão é feita em uma linha, com os valores separados por espaço em branco. 67 | * ATENÇÃO: método 'acoplado' ao Console como objeto de saída (pode ser melhorado). 68 | * @param vetor O vetor a ser impresso. 69 | */ 70 | static void imprimir(int[] vetor){ 71 | for (int i = 0; i < vetor.length; i++) 72 | System.out.print(vetor[i]+" "); 73 | } 74 | 75 | 76 | 77 | public static void main(String[] args) throws Exception { //atenção para modularidade e 'código limpo' 78 | final int TAMANHO; 79 | int[] inteiros; 80 | 81 | System.out.print("Quantos números você deseja ler/armazenar? "); 82 | TAMANHO = Integer.parseInt(leitor.nextLine()); 83 | 84 | inteiros = lerVetor(TAMANHO); 85 | inverterVetor(inteiros); 86 | System.out.println("\nInvertido:"); 87 | imprimir(inteiros); 88 | System.out.println(); 89 | 90 | System.out.println("\nFIM.\n"); 91 | leitor.close(); 92 | } 93 | 94 | 95 | } --------------------------------------------------------------------------------