This file contains hidden or 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
| import java.util.Arrays; | |
| import java.util.List; | |
| public class Main { | |
| public static void main(String[] args) { | |
| List<Integer> numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
| int somaQuadrados = calcularSomaQuadrados(numeros); | |
| System.out.println("A soma dos quadrados é: " + somaQuadrados); |
This file contains hidden or 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
| public class Carro { | |
| // Atributos | |
| private String marca; | |
| private String modelo; | |
| private int ano; | |
| // Construtor | |
| public Carro(String marca, String modelo, int ano) { | |
| this.marca = marca; | |
| this.modelo = modelo; |
This file contains hidden or 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
| import java.util.Arrays; | |
| import java.util.List; | |
| public class Main { | |
| public static void main(String[] args) { | |
| List<Integer> numeros = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); | |
| int somaQuadradosPares = numeros.stream() | |
| .filter(numero -> numero % 2 == 0) // Filtrando os números pares | |
| .mapToInt(numero -> numero * numero) // Mapeando para o quadrado do número |
This file contains hidden or 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
| public class CalculadoraMedia { | |
| public static void main(String[] args) { | |
| // Definindo os números | |
| double numero1 = 10.5; | |
| double numero2 = 8.2; | |
| double numero3 = 5.7; | |
| // Calculando a média | |
| double media = (numero1 + numero2 + numero3) / 3; |
This file contains hidden or 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
| // Interface alvo (target) | |
| interface Pessoa { | |
| String getNome(); | |
| String getIdentificador(); | |
| } | |
| // Classe adaptada - Pessoa Física | |
| class PessoaFisica { | |
| private String nome; | |
| private String cpf; |
This file contains hidden or 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
| // Interface Strategy | |
| interface Strategy { | |
| int execute(int a, int b); | |
| } | |
| // Implementações concretas das estratégias | |
| class AddStrategy implements Strategy { | |
| @Override | |
| public int execute(int a, int b) { | |
| return a + b; |
This file contains hidden or 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
| // Interface Componente | |
| interface Pessoa { | |
| double calcularPeso(); | |
| } | |
| // Classe Concreta Componente | |
| class PessoaBase implements Pessoa { | |
| private double peso; | |
| public PessoaBase(double peso) { |
This file contains hidden or 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
| import java.util.ArrayList; | |
| import java.util.List; | |
| // Interface do Observador | |
| interface Observer { | |
| void update(String message); | |
| } | |
| // Classe Concreta do Observador | |
| class ConcreteObserver implements Observer { |
This file contains hidden or 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
| public class Singleton { | |
| // Instância estática privada da classe | |
| private static Singleton instance; | |
| // Construtor privado para evitar a criação de instâncias fora da classe | |
| private Singleton() { | |
| // Construtor vazio ou com inicializações necessárias | |
| } | |
| // Método estático público para obter a instância única da classe |
This file contains hidden or 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
| // Interface para representar diferentes formas geométricas | |
| interface Shape { | |
| void draw(); | |
| } | |
| // Implementação da interface para um círculo | |
| class Circle implements Shape { | |
| @Override | |
| public void draw() { | |
| System.out.println("Desenhando um círculo"); |