├── README.md ├── TrabalhoJava ├── TrabalhoMapear.java └── CalculadoraGastoViagem │ └── CustoViagem.java ├── ProvaCorrecao ├── App.java └── Resolucao.java ├── Matriz ├── App.java └── MatrizExemplo.java ├── ExemploVetores ├── App.java └── Vetores.java ├── IteracaoFor ├── App.java └── ExemploFor.java ├── PooHeranca ├── App.java ├── Funcionarios.java ├── Professores.java ├── Pessoas.java └── Alunos.java ├── EstruturaDecisaoSwitch ├── App.java ├── SwitchCase.java └── Exercicio.java ├── EstruturaDecisaoIF ├── App.java └── DecisaoIf.java ├── ExercicioOperadores ├── App.java └── Exercicio.java ├── ExercíciosIfElse2 ├── App.java └── Exercicios.java ├── IteracaoWhile ├── App.java ├── ExemploWhile.java └── ExerciciosWhile.java ├── ExerciciosIfElse ├── App.java ├── ExerciciosPT2.java └── Exercicios.java ├── ExercicioGrupo ├── App.java └── Exercicio.java ├── ForWhileExerciciosExtras ├── App.java └── Exercicios.java ├── ListaAtividadeFormativa ├── App.java └── Exercicios.java ├── MatrizesExerciciosExtras ├── App.java └── Exercicios.java ├── CalculadoraDeDescontos ├── App.java └── CalcularDesconto.java ├── CalculadoraVelocidade2 ├── App.java └── CalculadoraVelocidade.java ├── Operadores ├── App.java └── Operadores.java ├── ProjetoFinalTestes ├── App.java ├── Pessoa.java └── Banco.java ├── PooInterface ├── FigurasGeometricas.java ├── Retangulo.java ├── App.java ├── Quadrado │ └── Quadrado.java └── Trapezio.java ├── ProjetoFinalSemestre ├── Pessoa.java ├── Main.java └── Conta.java ├── ExerciciosPooHeranca ├── App.java └── Pessoas.java ├── PooExercicio2 ├── App.java └── Agenda.java ├── PooExercicio3 ├── App.java └── Elevador.java └── PooIntroducao ├── App.java └── RegistraAluno.java /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /TrabalhoJava/TrabalhoMapear.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ProvaCorrecao/App.java: -------------------------------------------------------------------------------- 1 | package ProvaCorrecao; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Matriz/App.java: -------------------------------------------------------------------------------- 1 | package Matriz; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | MatrizExemplo obj1 = new MatrizExemplo(); 6 | obj1.exercicio1(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ExemploVetores/App.java: -------------------------------------------------------------------------------- 1 | package ExemploVetores; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Vetores obj = new Vetores(); 6 | obj.exercicio2();; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /IteracaoFor/App.java: -------------------------------------------------------------------------------- 1 | package IteracaoFor; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | ExemploFor obj1 = new ExemploFor(); 6 | obj1.exercicio1(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /PooHeranca/App.java: -------------------------------------------------------------------------------- 1 | package PooHeranca; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Alunos aluno1 = new Alunos(); 6 | aluno1.setNome("Alberto Silva"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /EstruturaDecisaoSwitch/App.java: -------------------------------------------------------------------------------- 1 | package EstruturaDecisaoSwitch; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicio obj = new Exercicio(); 6 | obj.mes(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /EstruturaDecisaoIF/App.java: -------------------------------------------------------------------------------- 1 | package EstruturaDecisaoIF; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | DecisaoIf obj1 = new DecisaoIf(); 6 | obj1.descontoIfElse(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ExercicioOperadores/App.java: -------------------------------------------------------------------------------- 1 | package ExercicioOperadores; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicio objeto1 = new Exercicio(); 6 | objeto1.nota(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ExercíciosIfElse2/App.java: -------------------------------------------------------------------------------- 1 | package ExercíciosIfElse2; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicios obj1 = new Exercicios(); 6 | obj1.exercicio1(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /IteracaoWhile/App.java: -------------------------------------------------------------------------------- 1 | package IteracaoWhile; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | ExerciciosWhile obj1 = new ExerciciosWhile(); 6 | obj1.exercicio1(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ExerciciosIfElse/App.java: -------------------------------------------------------------------------------- 1 | package ExerciciosIfElse; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | ExerciciosPT2 obj1 = new ExerciciosPT2(); 6 | obj1.exercicio11(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ExercicioGrupo/App.java: -------------------------------------------------------------------------------- 1 | package ExercicioGrupo; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicio obj1 = new Exercicio(); 6 | obj1.exercicio(); 7 | 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ForWhileExerciciosExtras/App.java: -------------------------------------------------------------------------------- 1 | package ForWhileExerciciosExtras; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicios obj1 = new Exercicios(); 6 | obj1.exercicio5(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ListaAtividadeFormativa/App.java: -------------------------------------------------------------------------------- 1 | package ListaAtividadeFormativa; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicios obj1 = new Exercicios(); 6 | obj1.exercicio3(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /MatrizesExerciciosExtras/App.java: -------------------------------------------------------------------------------- 1 | package MatrizesExerciciosExtras; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Exercicios obj1 = new Exercicios(); 6 | obj1.exercicio6(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /CalculadoraDeDescontos/App.java: -------------------------------------------------------------------------------- 1 | package CalculadoraDeDescontos; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | CalcularDesconto cDesconto = new CalcularDesconto(); 6 | cDesconto.calcular(); 7 | cDesconto.calcular30(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CalculadoraVelocidade2/App.java: -------------------------------------------------------------------------------- 1 | package CalculadoraVelocidade2; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | CalculadoraVelocidade objeto1 = new CalculadoraVelocidade(); 6 | objeto1.calcular(); 7 | objeto1.destino(); 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Operadores/App.java: -------------------------------------------------------------------------------- 1 | package Operadores; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | Operadores objeto1 = new Operadores(); 6 | objeto1.aritimetico(); 7 | objeto1.atribuicao(); 8 | objeto1.relacionais(); 9 | objeto1.logicos(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ProjetoFinalTestes/App.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalTestes; 2 | 3 | import java.util.jar.Manifest; 4 | 5 | import ProjetoFinalSemestre.Conta; 6 | 7 | public class App { 8 | public static void main(String[] args) { 9 | Banco objConta = new Banco("Pedrinho",21,0,1,"Conta PF"); 10 | 11 | 12 | objConta.exibirConta(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /PooInterface/FigurasGeometricas.java: -------------------------------------------------------------------------------- 1 | package PooInterface; 2 | 3 | public interface FigurasGeometricas { 4 | // somente modelos para outras classes 5 | // não podemos instanciar objetos desta classe 6 | // métodos abstratos por padrão/default 7 | 8 | public String getNomeFigura(); 9 | 10 | public double getArea(); 11 | 12 | public double getPerimetro(); 13 | } 14 | -------------------------------------------------------------------------------- /PooHeranca/Funcionarios.java: -------------------------------------------------------------------------------- 1 | package PooHeranca; 2 | 3 | public class Funcionarios extends Pessoas{ 4 | //subclasse de pessoas 5 | // atributos específicos 6 | private int salario; 7 | private String empresa; 8 | @Override 9 | public void setRg() { 10 | // TODO Auto-generated method stub 11 | throw new UnsupportedOperationException("Unimplemented method 'setRg'"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ProjetoFinalSemestre/Pessoa.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalSemestre; 2 | 3 | public class Pessoa { 4 | public String nome; 5 | public int idade; 6 | 7 | public String getNome() { 8 | return nome; 9 | } 10 | public void setNome(String nome) { 11 | this.nome = nome; 12 | } 13 | public int getIdade() { 14 | return idade; 15 | } 16 | public void setIdade(int idade) { 17 | this.idade = idade; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ExerciciosPooHeranca/App.java: -------------------------------------------------------------------------------- 1 | package ExerciciosPooHeranca; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | public class App { 6 | public static void main(String[] args) { 7 | Pessoas pessoa1 = new Pessoas(); 8 | pessoa1.setNome(JOptionPane.showInputDialog("Informe o nome: ")); 9 | pessoa1.setAltura(1.80); 10 | pessoa1.setAnoNascimento(2006); 11 | pessoa1.setMesNascimento(2); 12 | pessoa1.setDiaNascimento(6); 13 | 14 | pessoa1.imprimir(); 15 | pessoa1.idade(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ProjetoFinalTestes/Pessoa.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalTestes; 2 | 3 | public class Pessoa { 4 | public String nome; 5 | public int idade; 6 | 7 | public Pessoa(String nome, int idade) { 8 | this.nome = nome; 9 | this.idade = idade; 10 | } 11 | 12 | public String getNome() { 13 | return nome; 14 | } 15 | public void setNome(String nome) { 16 | this.nome = nome; 17 | } 18 | public int getIdade() { 19 | return idade; 20 | } 21 | public void setIdade(int idade) { 22 | this.idade = idade; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /PooInterface/Retangulo.java: -------------------------------------------------------------------------------- 1 | package PooInterface; 2 | 3 | public class Retangulo implements FigurasGeometricas{ 4 | 5 | // atributos do retangulo 6 | int base; 7 | int altura; 8 | 9 | // gerar o construtor 10 | public Retangulo(int base, int altura) { 11 | this.base = base; 12 | this.altura = altura; 13 | } 14 | 15 | // métodos override 16 | @Override 17 | public double getArea() { 18 | return base*altura; 19 | } 20 | 21 | @Override 22 | public String getNomeFigura() { 23 | return "Retângulo"; 24 | } 25 | 26 | @Override 27 | public double getPerimetro() { 28 | return (base + altura) * 2; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TrabalhoJava/CalculadoraGastoViagem/CustoViagem.java: -------------------------------------------------------------------------------- 1 | package TrabalhoJava.CalculadoraGastoViagem; 2 | 3 | public class CustoViagem { 4 | public static void main(String[] args) { 5 | // Escrever o programa 6 | System.out.println("A distância percorrida é"); 7 | double distanciaPercorrida = 148; 8 | System.out.println("O valor do combustível é"); 9 | double valorCombustível = 5; 10 | System.out.println("O valor que o carro gasta por litro é"); 11 | double valorGastoCarro = 10; 12 | double valorTotal = distanciaPercorrida/valorGastoCarro*valorCombustível; 13 | System.out.println("O valor que você gastará de Limeira até São Paulo será de " + valorTotal + " Reais"); 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PooInterface/App.java: -------------------------------------------------------------------------------- 1 | package PooInterface; 2 | 3 | import PooInterface.Quadrado.Quadrado; 4 | 5 | public class App { 6 | public static void main(String[] args) { 7 | Quadrado figura1 = new Quadrado(8); // um parâmetro 8 | Retangulo figura2 = new Retangulo(10, 5); // dois parâmetros 9 | Trapezio figura3 = new Trapezio(10, 5, 4, 2, 2); 10 | 11 | System.out.println(figura1.getNomeFigura() + "\n Area: " + figura1.getArea() + "\n Perímetro: " + figura1.getPerimetro()); 12 | System.out.println(figura2.getNomeFigura() + "\n Area: " + figura2.getArea() + "\n Perímetro: " + figura2.getPerimetro()); 13 | System.out.println(figura3.getNomeFigura() + "\n Area: " + figura3.getArea() + "\n Perímetro: " + figura3.getPerimetro()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /PooHeranca/Professores.java: -------------------------------------------------------------------------------- 1 | package PooHeranca; 2 | 3 | public class Professores extends Pessoas { 4 | //subclasse de pessoas 5 | // atributos específicos 6 | private String materia; 7 | private int salario; 8 | 9 | // métodos 10 | public String getMateria() { 11 | return materia; 12 | } 13 | public void setMateria(String materia) { 14 | this.materia = materia; 15 | } 16 | public int getSalario() { 17 | return salario; 18 | } 19 | public void setSalario(int salario) { 20 | this.salario = salario; 21 | } 22 | @Override 23 | public void setRg() { 24 | // TODO Auto-generated method stub 25 | throw new UnsupportedOperationException("Unimplemented method 'setRg'"); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /ExercíciosIfElse2/Exercicios.java: -------------------------------------------------------------------------------- 1 | package ExercíciosIfElse2; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Exercicios { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // exercício 1 da lista 2 9 | public void exercicio1() { 10 | System.out.println("Digite um número: "); 11 | double numero = sc.nextDouble(); 12 | 13 | if(numero > 10) { 14 | System.out.println("O número que você digitou é maior do que 10"); 15 | } 16 | else if(numero < 10) { 17 | System.out.println("O número que você digitou é menor do que 10"); 18 | } 19 | else { 20 | System.out.println("O número que você digitou é exatamente 10"); 21 | } 22 | 23 | } 24 | 25 | // exercício 2 26 | public void exercicio2() { 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /PooInterface/Quadrado/Quadrado.java: -------------------------------------------------------------------------------- 1 | package PooInterface.Quadrado; 2 | 3 | import PooInterface.FigurasGeometricas; 4 | 5 | public class Quadrado implements FigurasGeometricas { 6 | 7 | // assinou um contrato com figuras geométricas 8 | // obrigatoriamente declarar os métodos da class FigurasGeométricas 9 | 10 | // atributos da classe quadrado 11 | int lado; 12 | 13 | // construtor com parâmetro 14 | public Quadrado(int lado) { 15 | this.lado = lado; 16 | } 17 | 18 | 19 | // métodos importados de FigurasGeométricas 20 | @Override 21 | public double getArea() { 22 | int area = lado * lado; 23 | return area; 24 | } 25 | 26 | @Override 27 | public String getNomeFigura() { 28 | return "Quadrado"; 29 | } 30 | 31 | @Override 32 | public double getPerimetro() { 33 | int perimetro = lado*4; 34 | return perimetro; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /CalculadoraVelocidade2/CalculadoraVelocidade.java: -------------------------------------------------------------------------------- 1 | package CalculadoraVelocidade2; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CalculadoraVelocidade { 6 | Scanner sc = new Scanner(System.in); 7 | public void calcular(){ 8 | System.out.println("Informe a distância percorrida"); 9 | double distanciaPercorrida = sc.nextDouble(); 10 | System.out.println("Informe o Tempo Gasto"); 11 | double tempoGasto = sc.nextDouble(); 12 | double velocidadeMedia = distanciaPercorrida / tempoGasto; 13 | System.out.println("A velocidade média é " + velocidadeMedia + "Km/H"); 14 | 15 | 16 | } 17 | public void destino(){ // atividade extra 18 | System.out.println("Informe o Ponto de Partida"); 19 | String origem = sc.next(); 20 | System.out.println("Informe o Ponto de Destino"); 21 | String destino = sc.next(); 22 | System.out.println("Sua viagem é de " + origem + " até " + destino); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /PooInterface/Trapezio.java: -------------------------------------------------------------------------------- 1 | package PooInterface; 2 | 3 | public class Trapezio implements FigurasGeometricas { 4 | 5 | // atributos do trapézio 6 | int baseMaior; 7 | int baseMenor; 8 | int altura; 9 | int ladoUm; 10 | int ladoDois; 11 | 12 | // gerar o construtor 13 | public Trapezio(int baseMaior, int baseMenor, int altura, int ladoUm, int ladoDois) { 14 | this.baseMaior = baseMaior; 15 | this.baseMenor = baseMenor; 16 | this.altura = altura; 17 | this.ladoUm = ladoUm; 18 | this.ladoDois = ladoDois; 19 | } 20 | 21 | @Override 22 | public double getArea() { 23 | return ((baseMaior + baseMenor) * altura) / 2; 24 | } 25 | 26 | @Override 27 | public String getNomeFigura() { 28 | return "Trapézio"; 29 | } 30 | 31 | @Override 32 | public double getPerimetro() { 33 | return baseMaior+baseMenor+ladoUm+ladoDois; 34 | } 35 | 36 | // métodos override 37 | 38 | } 39 | -------------------------------------------------------------------------------- /EstruturaDecisaoSwitch/SwitchCase.java: -------------------------------------------------------------------------------- 1 | package EstruturaDecisaoSwitch; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SwitchCase { 6 | Scanner sc = new Scanner(System.in); 7 | public void letra(){ 8 | //1. receber a letra digitada pelo usuário 9 | System.out.println("Informe uma Letra: "); 10 | String letra = sc.nextLine(); 11 | //2. escolher o resultado referente a letra 12 | String tipoLetra = ""; 13 | switch (letra) { 14 | case "a": tipoLetra = "vogal"; 15 | break; 16 | case "e": tipoLetra = "vogal"; 17 | break; 18 | case "i": tipoLetra = "vogal"; 19 | break; 20 | case "o": tipoLetra = "vogal"; 21 | break; 22 | case "u": tipoLetra = "vogal"; 23 | break; 24 | default: tipoLetra = "consoante"; 25 | break; 26 | } 27 | //3. mostrar o resultado para o usuário 28 | System.out.println(letra + " é do tipo " + tipoLetra); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /PooHeranca/Pessoas.java: -------------------------------------------------------------------------------- 1 | package PooHeranca; 2 | 3 | public abstract class Pessoas { 4 | //super classe (fornecer herança para as outras classes 5 | // atributos genéricos (comuns a todas as classes herdeiras) 6 | // atributos 7 | String nome; 8 | String endereco; 9 | int idade; 10 | String cpf; 11 | String rg; 12 | 13 | public String getRg() { 14 | return rg; 15 | } 16 | public abstract void setRg(); 17 | // métodos 18 | public String getNome() { 19 | return nome; 20 | } 21 | public void setNome(String nome) { 22 | this.nome = nome; 23 | } 24 | public String getEndereco() { 25 | return endereco; 26 | } 27 | public void setEndereco(String endereco) { 28 | this.endereco = endereco; 29 | } 30 | public int getIdade() { 31 | return idade; 32 | } 33 | public void setIdade(int idade) { 34 | this.idade = idade; 35 | } 36 | public String getCpf() { 37 | return cpf; 38 | } 39 | public void setCpf(String cpf) { 40 | this.cpf = cpf; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /PooExercicio2/App.java: -------------------------------------------------------------------------------- 1 | package PooExercicio2; 2 | 3 | import java.util.Random; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | public class App { 8 | public static void main(String[] args) { 9 | Random rd = new Random(); 10 | // criar um vetor para 10 objetos 11 | Agenda contatos[] = new Agenda[10]; 12 | //criar os objetos e preencher as informações 13 | for (int i = 0; i < contatos.length; i++) { 14 | // criar o objeto - construtor 15 | contatos[i] = new Agenda(); 16 | // preencher os atributos 17 | contatos[i].setNome(JOptionPane.showInputDialog("Digite o nome: ")); 18 | contatos[i].setAltura(rd.nextInt(200)/100); 19 | contatos[i].setIdade(i + 18); 20 | } 21 | 22 | // criar um método para achar a pessoa do Array 23 | String buscaNome = JOptionPane.showInputDialog("Informe o nome a ser buscado"); 24 | boolean busca = true; 25 | int cont=0; 26 | 27 | while(busca) { 28 | if(buscaNome.equals(contatos[cont].getNome())){ 29 | busca = false; 30 | contatos[cont].imprimir(); 31 | } 32 | cont++; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /ExercicioOperadores/Exercicio.java: -------------------------------------------------------------------------------- 1 | package ExercicioOperadores; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Exercicio { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | public void nota() { 9 | System.out.println("Informe a nota 1"); 10 | int notaUm = sc.nextInt(); 11 | System.out.println("Informe a nota 2"); 12 | int notaDois = sc.nextInt(); 13 | 14 | // operação aritimética 15 | double médiaPonderada = (notaUm + notaDois) / 2; 16 | System.out.println("A média do aluno é " + médiaPonderada); 17 | 18 | // operação relacional 19 | boolean mediaAprovada = médiaPonderada>= 50; 20 | System.out.println("O aluno está aprovado por nota? " +mediaAprovada); 21 | System.out.println("Informe a frequência do aluno"); 22 | int frequenciaAluno = sc.nextInt(); 23 | boolean frequenciaAprovada = frequenciaAluno>= 75; 24 | System.out.println("O aluno está reprovado por frequência? " + frequenciaAprovada); 25 | 26 | // Operação lógica 27 | boolean resultadoFinal = (mediaAprovada==true) && (frequenciaAprovada==true); 28 | System.out.println("O aluno está aprovado no curso? " + resultadoFinal); 29 | sc.close(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /PooHeranca/Alunos.java: -------------------------------------------------------------------------------- 1 | package PooHeranca; 2 | 3 | public class Alunos extends Pessoas { 4 | //subclasse de pessoas 5 | // atributos específicos 6 | 7 | private int nMatricula; 8 | private String curso; 9 | private double mediaSemestre; 10 | private String turma; 11 | 12 | // métodos 13 | public int getnMatricula() { 14 | return nMatricula; 15 | } 16 | public void setnMatricula(int nMatricula) { 17 | this.nMatricula = nMatricula; 18 | } 19 | public String getCurso() { 20 | return curso; 21 | } 22 | public void setCurso(String curso) { 23 | this.curso = curso; 24 | } 25 | public double getMediaSemestre() { 26 | return mediaSemestre; 27 | } 28 | public void setMediaSemestre(double mediaSemestre) { 29 | this.mediaSemestre = mediaSemestre; 30 | } 31 | public String getTurma() { 32 | return turma; 33 | } 34 | public void setTurma(String turma) { 35 | this.turma = turma; 36 | } 37 | @Override 38 | public void setRg() { 39 | // TODO Auto-generated method stub 40 | throw new UnsupportedOperationException("Unimplemented method 'setRg'"); 41 | } 42 | 43 | public void setRg(String rg){ 44 | this.rg = "SP" + "número"; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /PooExercicio2/Agenda.java: -------------------------------------------------------------------------------- 1 | package PooExercicio2; 2 | import java.util.Scanner; 3 | 4 | import javax.swing.JOptionPane; 5 | 6 | public class Agenda { 7 | Scanner sc = new Scanner(System.in); 8 | // atributos 9 | String nome; 10 | double altura; 11 | int idade; 12 | 13 | // métodos 14 | // construtor com parâmetros 15 | public Agenda(String nome, double altura, int idade) { 16 | this.nome = nome; 17 | this.altura = altura; 18 | this.idade = idade; 19 | } 20 | 21 | // construtor vazio 22 | public Agenda() { 23 | 24 | } 25 | 26 | // getters and setters 27 | public String getNome() { 28 | return nome; 29 | } 30 | 31 | public void setNome(String nome) { 32 | this.nome = nome; 33 | } 34 | 35 | public double getAltura() { 36 | return altura; 37 | } 38 | 39 | public void setAltura(double altura) { 40 | this.altura = altura; 41 | } 42 | 43 | public int getIdade() { 44 | return idade; 45 | } 46 | 47 | public void setIdade(int idade) { 48 | this.idade = idade; 49 | } 50 | 51 | // métodos de aplicações dievrsas 52 | // void 53 | 54 | 55 | public void imprimir() { 56 | JOptionPane.showMessageDialog(null, "Nome: " + nome + "\n Altura: " + altura + "\nIdade: " + idade); 57 | } 58 | } -------------------------------------------------------------------------------- /EstruturaDecisaoIF/DecisaoIf.java: -------------------------------------------------------------------------------- 1 | package EstruturaDecisaoIF; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DecisaoIf { 6 | Scanner sc = new Scanner(System.in); 7 | public void descontoIF() { 8 | System.out.println("Informe o preço do produto: "); 9 | double precoProduto = sc.nextDouble(); 10 | double desconto = 0.0; 11 | if(precoProduto>=100 && precoProduto < 200) { 12 | desconto = 5.0; // porcento 13 | } 14 | if(precoProduto>=200 && precoProduto < 300) { 15 | desconto = 10.0; // porcento 16 | } 17 | if(precoProduto>=300) { 18 | desconto = 15.0; // porcento 19 | } 20 | // calculo do desconto 21 | double valorDesconto = precoProduto*desconto/100; 22 | double precoFinal = precoProduto - valorDesconto; 23 | System.out.println("O valor do produto é R$" +precoFinal); 24 | } 25 | public void descontoIfElse() { 26 | System.out.println("Informe o preço do produto: "); 27 | double precoProduto = sc.nextDouble(); 28 | double desconto; 29 | if(precoProduto >=300) { 30 | desconto = 15.0; 31 | } 32 | else if (precoProduto>=200) { 33 | desconto = 10.0; 34 | }else if (precoProduto>=100){ 35 | desconto = 5.0; 36 | }else{ 37 | desconto = 0.0; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /IteracaoWhile/ExemploWhile.java: -------------------------------------------------------------------------------- 1 | package IteracaoWhile; 2 | 3 | import java.util.Random; 4 | import java.util.Scanner; 5 | 6 | public class ExemploWhile { 7 | Scanner sc = new Scanner(System.in); 8 | 9 | public void exemplo1() { 10 | int i=0; 11 | 12 | while(i>-1) { // irá fazer um loop infinito 13 | System.out.println("O n° da iteração é " + i); 14 | i++; // i=i + 1; i+=1; 15 | } 16 | } 17 | 18 | public void exemplo2() { 19 | int vetor [] = new int[10]; 20 | int i=0; 21 | 22 | while (i<10) { 23 | System.out.println("Informe o valor do vetor["+i+"]="); 24 | vetor[i]=sc.nextInt(); 25 | i++; 26 | } 27 | while(i>0) { 28 | i--; 29 | System.out.println("vetor["+i+"]=" + vetor[i]); 30 | } 31 | } 32 | 33 | public void exemplo3() { 34 | Random rd = new Random(); 35 | int nAleatorio = rd.nextInt(10)+1; 36 | boolean TenteNovamente = true; 37 | 38 | while(TenteNovamente) { 39 | System.out.println("Digite um n° de 1 a 10"); 40 | int nDigitado = sc.nextInt(); 41 | if(nDigitado == nAleatorio) { 42 | System.out.println("Acertouuuuuu"); 43 | TenteNovamente = false; 44 | } else{ 45 | System.out.println("Errouuuuuuu"); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /PooExercicio3/App.java: -------------------------------------------------------------------------------- 1 | package PooExercicio3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class App { 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | Elevador elevador1 = new Elevador(10, 10); 9 | 10 | //iniciar 11 | elevador1.inicializa(); 12 | boolean ligado = true; 13 | // loop do elevador 14 | while(ligado){ 15 | System.out.println("Digite a ação desejada: " + "\n Entrar: " + "\n Sair: " + "\n Subir: " + "\n Descer: " + "\n Desligar: "); 16 | int acao = sc.nextInt(); 17 | switch (acao) { 18 | case 1: 19 | System.out.println("Capacidade atual: " + elevador1.entra()); 20 | break; 21 | 22 | case 2: 23 | System.out.println("Capacidade atual: " + elevador1.sair()); 24 | break; 25 | 26 | case 3: 27 | System.out.println("Capacidade atual: " + elevador1.subir(sc.nextInt())); 28 | break; 29 | 30 | case 4: 31 | System.out.println("Capacidade atual: " + elevador1.descer(sc.nextInt())); 32 | break; 33 | 34 | case 5: 35 | ligado = false; 36 | 37 | default: 38 | System.out.println("Digite uma ação válida: "); 39 | break; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /EstruturaDecisaoSwitch/Exercicio.java: -------------------------------------------------------------------------------- 1 | package EstruturaDecisaoSwitch; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Exercicio { 6 | Scanner sc = new Scanner(System.in); 7 | public void mes() { 8 | System.out.println("Informe o número referente ao mês: "); 9 | int numero = sc.nextInt(); 10 | 11 | String tipoMes = ""; 12 | switch (numero) { 13 | case 1: tipoMes = "Janeiro"; 14 | break; 15 | 16 | case 2: tipoMes = "Fevereiro"; 17 | break; 18 | 19 | case 3: tipoMes = "Março"; 20 | break; 21 | 22 | case 4: tipoMes = "Abril"; 23 | break; 24 | 25 | case 5: tipoMes = "Maio"; 26 | break; 27 | 28 | case 6: tipoMes = "Junho"; 29 | break; 30 | 31 | case 7: tipoMes = "Julho"; 32 | break; 33 | 34 | case 8: tipoMes = "Agosto"; 35 | break; 36 | 37 | case 9: tipoMes = "Setembro"; 38 | break; 39 | 40 | case 10: tipoMes = "Outubro"; 41 | break; 42 | 43 | case 11: tipoMes = "Novembro"; 44 | break; 45 | 46 | case 12: tipoMes = "Dezembro"; 47 | break; 48 | 49 | default: tipoMes = "Não é um mês válido!"; 50 | break; 51 | } 52 | System.out.println("O número " + numero + " pertence ao mês de " + tipoMes); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /PooIntroducao/App.java: -------------------------------------------------------------------------------- 1 | package PooIntroducao; 2 | 3 | public class App { 4 | public static void main(String[] args) { 5 | // criando objetos 6 | RegistraAluno aluno1 = new RegistraAluno(); 7 | RegistraAluno aluno2 = new RegistraAluno(); 8 | 9 | // setando os atributos com set 10 | aluno1.setNome("Ana Carla Pereira"); 11 | aluno1.setIdade(18); 12 | aluno1.setEndereco("Rua das paineiras"); 13 | aluno1.setNotaCiencias(6); 14 | aluno1.setNotaMatematica(10); 15 | aluno1.setNotaPortugues(4); 16 | 17 | 18 | aluno2.setNome("Carlos"); 19 | aluno2.setIdade(15); 20 | aluno2.setEndereco("Rua dos bobos"); 21 | aluno2.setNotaCiencias(3); 22 | aluno2.setNotaMatematica(5); 23 | aluno2.setNotaPortugues(8); 24 | 25 | // mostrando os atributos com get 26 | System.out.println("Nome: " + aluno1.getNome()); 27 | System.out.println("Idade: " + aluno1.getIdade()); 28 | System.out.println("Endereço: " + aluno1.getEndereco()); 29 | System.out.println("Média: " + aluno1.getMedia()); 30 | 31 | System.out.println("====================================================="); 32 | 33 | System.out.println("Nome: " + aluno2.getNome()); 34 | System.out.println("Idade: " + aluno2.getIdade()); 35 | System.out.println("Endereço: " + aluno2.getEndereco()); 36 | System.out.println("Média: " + aluno2.getMedia()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /CalculadoraDeDescontos/CalcularDesconto.java: -------------------------------------------------------------------------------- 1 | package CalculadoraDeDescontos; 2 | 3 | public class CalcularDesconto { 4 | public void calcular() { 5 | System.out.println("==============="); 6 | double precoProduto; 7 | precoProduto = 200; 8 | System.out.println("O preço do produto é de " + precoProduto + "reais"); 9 | double percentualDesconto = 10.0; 10 | percentualDesconto = 20; 11 | System.out.println("O desconto será de " + percentualDesconto + "%."); 12 | // regra de três para descobrir qual o valor do desconto 13 | double desconto = precoProduto*percentualDesconto/100; 14 | double precoComDesconto = precoProduto - desconto; 15 | System.out.println("Com desconto, o produto sai " + "por R$" + precoComDesconto + "."); 16 | System.out.println("Fim!"); 17 | System.out.println("==============="); 18 | } 19 | 20 | // desafio extra 21 | public void calcular30() { 22 | System.out.println("==============="); 23 | double precoProduto; 24 | precoProduto = 200; 25 | System.out.println("O preço do produto é de " + precoProduto + "reais"); 26 | double percentualDesconto = 10.0; 27 | percentualDesconto = 30; 28 | System.out.println("O desconto será de " + percentualDesconto + "%."); 29 | // regra de três para descobrir qual o valor do desconto 30 | double desconto = precoProduto*percentualDesconto/100; 31 | double precoComDesconto = precoProduto - desconto; 32 | System.out.println("Com desconto, o produto sai " + "por R$" + precoComDesconto + "."); 33 | System.out.println("Fim!"); 34 | System.out.println("==============="); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ExerciciosPooHeranca/Pessoas.java: -------------------------------------------------------------------------------- 1 | package ExerciciosPooHeranca; 2 | 3 | import javax.xml.crypto.Data; 4 | 5 | // exercício 1 da lista de exercícios do PDF 16 de POO (construtores) 6 | 7 | public class Pessoas { 8 | private String nome; 9 | private double altura; 10 | private int diaNascimento; 11 | private int mesNascimento; 12 | private int anoNascimento; 13 | 14 | // criar os métodos 15 | public String getNome() { 16 | return nome; 17 | } 18 | public void setNome(String nome) { 19 | this.nome = nome; 20 | } 21 | public double getAltura() { 22 | return altura; 23 | } 24 | public void setAltura(double altura) { 25 | this.altura = altura; 26 | } 27 | public int getDiaNascimento() { 28 | return diaNascimento; 29 | } 30 | public void setDiaNascimento(int diaNascimento) { 31 | this.diaNascimento = diaNascimento; 32 | } 33 | public int getMesNascimento() { 34 | return mesNascimento; 35 | } 36 | public void setMesNascimento(int mesNascimento) { 37 | this.mesNascimento = mesNascimento; 38 | } 39 | public int getAnoNascimento() { 40 | return anoNascimento; 41 | } 42 | public void setAnoNascimento(int anoNascimento) { 43 | this.anoNascimento = anoNascimento; 44 | } 45 | 46 | // métodos solicitados (void ou return) 47 | // printar todas as informações das pessoas 48 | 49 | public void imprimir() { 50 | System.out.println("Nome: " + nome); 51 | System.out.println("Altura: " + altura); 52 | System.out.println("Data de nascimento: " + diaNascimento + "/" + mesNascimento + "/" + anoNascimento); 53 | } 54 | 55 | // calcular a idade 56 | public void idade() { 57 | int idade =0; 58 | if(diaNascimento <=30 && mesNascimento<=5) { 59 | idade = 2023 - anoNascimento; 60 | } 61 | else { 62 | idade = 2023 - anoNascimento - 1; 63 | } 64 | System.out.println("A idade é: " + idade); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /PooExercicio3/Elevador.java: -------------------------------------------------------------------------------- 1 | package PooExercicio3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Elevador { 6 | Scanner sc = new Scanner(System.in); 7 | int nMaxAndares; 8 | int nMaxPessoas; 9 | int andarAtual; 10 | int qtdPessoasAtual; 11 | 12 | // métodos 13 | // construtor 14 | public Elevador(int nMaxAndares, int nMaxPessoas) { 15 | this.nMaxAndares = nMaxAndares; 16 | this.nMaxPessoas = nMaxPessoas; 17 | } 18 | 19 | //gets and sets 20 | public int getAndarAtual() { 21 | return andarAtual; 22 | } 23 | 24 | public void setAndarAtual(int andarAtual) { 25 | this.andarAtual = andarAtual; 26 | } 27 | 28 | public int getQtdPessoasAtual() { 29 | return qtdPessoasAtual; 30 | } 31 | 32 | public void setQtdPessoasAtual(int qtdPessoasAtual) { 33 | this.qtdPessoasAtual = qtdPessoasAtual; 34 | } 35 | 36 | // métodos próprios 37 | public void inicializa() { 38 | andarAtual = 0; 39 | qtdPessoasAtual = 0; 40 | } 41 | 42 | public int entra(){ 43 | if(qtdPessoasAtual0){ 53 | qtdPessoasAtual--; 54 | } else{ 55 | System.out.println("Não tem ninguém para descer"); 56 | } 57 | return qtdPessoasAtual; 58 | } 59 | 60 | public int subir(int nAndares) { 61 | if(andarAtual + nAndares <= nMaxAndares){ 62 | andarAtual+=nAndares; 63 | } else{ 64 | System.out.println("Digite um n° válido para subir"); 65 | } 66 | 67 | return andarAtual; 68 | } 69 | 70 | public int descer(int nAndares) { 71 | if(andarAtual - nAndares >= 0){ 72 | andarAtual-=nAndares; 73 | } else{ 74 | System.out.println("Digite um n° válido para descer"); 75 | } 76 | 77 | return andarAtual; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /PooIntroducao/RegistraAluno.java: -------------------------------------------------------------------------------- 1 | package PooIntroducao; 2 | 3 | public class RegistraAluno { 4 | // declaração dos atributos do objeto 5 | private String nome; 6 | private String endereco; 7 | private int idade; 8 | private double notaMatematica; 9 | private double notaPortugues; 10 | private double notaCiencias; 11 | 12 | // atributo da classe 13 | private static int contadorEstudante; 14 | 15 | // criação de metodos de acesso (get) 16 | // retorna o this. do estudante 17 | public String getNome() { 18 | return nome; 19 | } 20 | 21 | // retorna o endereço do estudante 22 | public String getEndereco() { 23 | return endereco; 24 | } 25 | 26 | // retorna idade do estudante 27 | public int getIdade() { 28 | return idade; 29 | } 30 | 31 | // retorna a média do estudante 32 | public double getMedia() { 33 | double resultado = 0; 34 | resultado = (notaMatematica 35 | + notaPortugues 36 | + notaCiencias) / 3; 37 | return resultado; 38 | } 39 | 40 | // retorna a quantidade de estudantes cadastrados 41 | public static int getQauntidadeAlunos() { 42 | return contadorEstudante; 43 | } 44 | 45 | // método de definição set 46 | // define ou altera o this. do estudante 47 | public void setNome(String nome) { 48 | this.nome = nome; 49 | } 50 | 51 | // define ou altera o endereço do estudante 52 | public void setEndereco(String endereco) { 53 | this.endereco = endereco; 54 | } 55 | 56 | // define ou altera o endereço do estudante 57 | public void setIdade(int idade) { 58 | this.idade = idade; 59 | } 60 | 61 | // define ou altera o endereço do estudante 62 | public void setNotaMatematica(double resultado) { 63 | notaMatematica = resultado; 64 | } 65 | 66 | // define ou altera o endereço do estudante 67 | public void setNotaPortugues(double resultado) { 68 | notaPortugues = resultado; 69 | } 70 | 71 | // define ou altera o endereço do estudante 72 | public void setNotaCiencias(double resultado) { 73 | notaCiencias = resultado; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /ProjetoFinalSemestre/Main.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalSemestre; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | /** 6 | * Main 7 | */ 8 | public class Main { 9 | 10 | public static void main(String[] args) { 11 | Conta[] Conta = new Conta[2]; 12 | Conta objConta = new Conta(); 13 | int receber, x = 0; 14 | do { 15 | JOptionPane.showMessageDialog(null, "Bem-vindo ao Banco!"); 16 | receber = Integer.parseInt(JOptionPane.showInputDialog("Pressione: 1 - Criar conta; 2 - Buscar conta")); 17 | switch (receber) { 18 | case 1: { 19 | for (int i = 0; i < Conta.length; i++) { 20 | Conta[i] = new Conta(); 21 | Conta[i].criarConta(); 22 | } 23 | break; 24 | } 25 | case 2: { 26 | int cont=0; 27 | JOptionPane.showMessageDialog(null, "Buscar Contas"); 28 | String buscarNome = JOptionPane.showInputDialog("Informe o nome da conta para ser buscado:"); 29 | boolean encontrar = true; 30 | while (encontrar) { 31 | if (buscarNome.equals(Conta[cont].getNome())) { 32 | JOptionPane.showMessageDialog(null, "Nome: " + Conta[cont].getNome()); 33 | JOptionPane.showMessageDialog(null, "Idade: " + Conta[cont].getIdade()); 34 | JOptionPane.showMessageDialog(null, "Código: " + Conta[cont].getCodigo()); 35 | JOptionPane.showMessageDialog(null, "Tipo da conta: " + Conta[cont].getContaTipo()); 36 | JOptionPane.showMessageDialog(null, "Saldo: " + Conta[cont].getSaldo()); 37 | encontrar = false; 38 | } else { 39 | JOptionPane.showMessageDialog(null, "Nome não encontrado."); 40 | } 41 | cont++; 42 | } 43 | break; 44 | } 45 | 46 | default: { 47 | JOptionPane.showMessageDialog(null, "Selecione uma dessas opções."); 48 | break; 49 | } 50 | } 51 | x = Integer.parseInt(JOptionPane.showInputDialog("Deseja continuar? 0 - Sim; 1 - Não")); 52 | } while (x == 0); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /IteracaoWhile/ExerciciosWhile.java: -------------------------------------------------------------------------------- 1 | package IteracaoWhile; 2 | 3 | public class ExerciciosWhile { 4 | public void exercicio1() { 5 | int vetorA[] = new int[] { 3, 5, 7, 11, 13 }; 6 | int vetorB[] = new int[vetorA.length]; 7 | int i = 0; 8 | 9 | while (i < vetorA.length) { 10 | vetorB[i] = vetorA[i]; 11 | System.out.println("VetorB[" + i + "]=" + vetorB[i]); 12 | i++; 13 | } 14 | } 15 | 16 | public void exercicio2() { 17 | int vetorA[] = new int[] { 6, 9, 7, 14, 12, 20, 21, 22 }; 18 | int vetorB[] = new int[vetorA.length]; 19 | int i = 0; 20 | 21 | while (i < vetorA.length) { 22 | vetorB[i] = vetorA[i] * 2; 23 | System.out.println("VetorB[" + i + "]=" + vetorB[i]); 24 | i++; 25 | } 26 | } 27 | 28 | public void exercicio3() { 29 | int vetorA[] = new int[] { 6, 9, 7, 14, 12, 20, 21, 22, 29, 31, 26, 43, 47, 52, 55 }; 30 | int vetorB[] = new int[vetorA.length]; 31 | int i = 0; 32 | 33 | while (i < vetorA.length) { 34 | vetorB[i] = vetorA[i] * vetorA[i]; 35 | System.out.println("VetorB[" + i + "]=" + vetorB[i]); 36 | i++; 37 | } 38 | } 39 | 40 | public void exercicio4() { 41 | int vetorA[] = new int[] { 6, 9, 7, 14, 12, 20, 21, 22, 29, 31, 26, 43, 47, 52, 55 }; 42 | double vetorB[] = new double[vetorA.length]; 43 | int i = 0; 44 | 45 | while (i < vetorA.length) { 46 | vetorB[i] = Math.sqrt(vetorA[i]); 47 | System.out.println("VetorB[" + i + "]=" + vetorB[i]); 48 | i++; 49 | } 50 | } 51 | 52 | public void exercicio5() { 53 | int vetorA[] = new int[] { 6, 9, 7, 14, 12, 20, 21, 22, 29, 31}; 54 | int vetorB[] = new int[vetorA.length]; 55 | int i = 0; 56 | 57 | while (i < vetorA.length) { 58 | vetorB[i] = vetorA[i] * i; 59 | System.out.println("VetorB[" + i + "]=" + vetorB[i]); 60 | i++; 61 | } 62 | } 63 | 64 | public void exercicio6() { 65 | int vetorA[] = new int[] { 6, 9, 7, 14, 12, 20, 21, 22, 29, 31}; 66 | int vetorB[] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 67 | int vetorC[] = new int[vetorA.length]; 68 | int i=0; 69 | 70 | while(i < vetorA.length) { 71 | vetorC[i] = vetorA[i] + vetorB[i]; 72 | System.out.println("VetorC[" + i + "]=" + vetorC[i]); 73 | i++; 74 | 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /ProvaCorrecao/Resolucao.java: -------------------------------------------------------------------------------- 1 | package ProvaCorrecao; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Resolucao { 6 | Scanner sc = new Scanner (System.in); 7 | 8 | public void exercicio1() { 9 | System.out.println("Informe o primeiro número:"); 10 | double numeroUm = sc.nextDouble(); 11 | 12 | System.out.println("Informe outro número"); 13 | double numeroDois = sc.nextDouble(); 14 | 15 | System.out.println("Informe a operação desejada"); 16 | System.out.println("1- Adição; 2- Subtração; 3- Multiplicação; 4- Divisão"); 17 | int operacao = sc.nextInt(); 18 | double resultado =sc.nextDouble(); 19 | 20 | if(operacao == 1) { 21 | resultado = numeroUm + numeroDois; 22 | System.out.println("O resultado é " + resultado); 23 | } else if(operacao == 2) { 24 | resultado = numeroUm - numeroDois; 25 | System.out.println("O resultado é " + resultado); 26 | } else if(operacao == 3) { 27 | resultado = numeroUm * numeroDois; 28 | System.out.println("O resultado é " + resultado); 29 | } else if(operacao == 4 && numeroDois != 0) { 30 | resultado = numeroUm / numeroDois; 31 | System.out.println("O resultado é " + resultado); 32 | } 33 | else { 34 | System.out.println("Operação inválida"); 35 | } 36 | } 37 | public void exercicio2() { 38 | System.out.println("Informe seu n° de matrícula: "); 39 | int nMatricula = sc.nextInt(); 40 | 41 | int grupo = nMatricula % 4; 42 | if(nMatricula == 0) { 43 | System.out.println("Time do Chris"); 44 | } else if(nMatricula == 1) { 45 | System.out.println("Time do Greg"); 46 | } else if(nMatricula == 2) { 47 | System.out.println("Time do Caruso"); 48 | } else { 49 | System.out.println("Time do Jerome"); 50 | } 51 | } 52 | 53 | public void exercicio3() { 54 | System.out.println("Kg de morango"); 55 | double kgMorango = sc.nextDouble(); 56 | 57 | System.out.println("Kg de maçã"); 58 | double kgMaca = sc.nextDouble(); 59 | 60 | System.out.println("Kg de banana"); 61 | double kgBanana = sc.nextDouble(); 62 | 63 | double pesoTotal = kgBanana + kgMaca + kgMorango; 64 | double valorTotal = kgBanana * 1.8 + kgMaca * 2.3 + kgMorango * 3.5; 65 | 66 | if(pesoTotal >= 15 || valorTotal >= 30) { 67 | valorTotal = valorTotal - valorTotal * 0.1; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /ExerciciosIfElse/ExerciciosPT2.java: -------------------------------------------------------------------------------- 1 | package ExerciciosIfElse; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ExerciciosPT2 { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | public void exercicio11(){ 9 | System.out.println("Informe o valor da sua hora: "); 10 | double valorHora = sc.nextDouble(); 11 | System.out.println("Informe quantas horas você trabalhou no mês: "); 12 | double horasTrabalhadas = sc.nextDouble(); 13 | double salarioBruto = valorHora * horasTrabalhadas; 14 | if(salarioBruto<=900) { 15 | System.out.println("Você está isento e não terá reajustes no salário"); 16 | } 17 | 18 | else if(salarioBruto>900 && salarioBruto<=1500) { 19 | double impostoRenda = (salarioBruto * 5) / 100; 20 | double inS = (salarioBruto * 10) / 100; 21 | double fGt = (salarioBruto * 11) / 100; 22 | double totalDescontos = impostoRenda + inS + fGt; 23 | double salarioLiquido = salarioBruto - totalDescontos; 24 | System.out.println("Salário bruto: " + salarioBruto); 25 | System.out.println("Desconto IR: " + impostoRenda); 26 | System.out.println("Desconto INSS: " + inS); 27 | System.out.println("Desconto FGTS: " + fGt); 28 | System.out.println("Total de descontos: " + totalDescontos); 29 | System.out.println("Seu salário líquido é: " + salarioLiquido); 30 | } 31 | else if(salarioBruto>1500 && salarioBruto <=2500) { 32 | double impostoRenda = (salarioBruto * 10) / 100; 33 | double inS = (salarioBruto * 10) / 100; 34 | double fGt = (salarioBruto * 11) / 100; 35 | double totalDescontos = impostoRenda + inS + fGt; 36 | double salarioLiquido = salarioBruto - totalDescontos; 37 | System.out.println("Salário bruto: " + salarioBruto); 38 | System.out.println("Desconto IR: " + impostoRenda); 39 | System.out.println("Desconto INSS: " + inS); 40 | System.out.println("Desconto FGTS: " + fGt); 41 | System.out.println("Total de descontos: " + totalDescontos); 42 | System.out.println("Seu salário líquido é: " + salarioLiquido); 43 | } 44 | else if(salarioBruto>2500) { 45 | double impostoRenda = (salarioBruto * 20) / 100; 46 | double inS = (salarioBruto * 10) / 100; 47 | double fGt = (salarioBruto * 11) / 100; 48 | double totalDescontos = impostoRenda + inS + fGt; 49 | double salarioLiquido = salarioBruto - totalDescontos; 50 | System.out.println("Salário bruto: " + salarioBruto); 51 | System.out.println("Desconto IR: " + impostoRenda); 52 | System.out.println("Desconto INSS: " + inS); 53 | System.out.println("Desconto FGTS: " + fGt); 54 | System.out.println("Total de descontos: " + totalDescontos); 55 | System.out.println("Seu salário líquido é: " + salarioLiquido); 56 | } 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /ExemploVetores/Vetores.java: -------------------------------------------------------------------------------- 1 | package ExemploVetores; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Vetores { 6 | 7 | Scanner sc = new Scanner(System.in); 8 | // criando método 9 | public void exemplo1() { 10 | // criando um vetor 11 | double[] valores = new double[] {11.7, 5, 123, 4.1}; 12 | System.out.println("1º Posição- Índice[0]:" + valores[0]); 13 | System.out.println("2º Posição- Índice[1]:" + valores[1]); 14 | System.out.println("3º Posição- Índice[2]:" + valores[2]); 15 | System.out.println("4º Posição- Índice[3]:" + valores[3]); 16 | 17 | //Mudando valores de uma posição definida 18 | valores[0] = 15.6; // Mudando o valor do índice [0] 19 | System.out.println("1º Posição- Índice[0]:" + valores[0]); 20 | } 21 | 22 | public void exemplo2() { 23 | // criando o vetor 24 | int[] novosValores = new int[5]; 25 | novosValores[0] = 15; 26 | novosValores[1] = 11; 27 | novosValores[2] = 17; 28 | novosValores[3] = 25; 29 | novosValores[4] = 6; 30 | System.out.println("O vetor é : posição [0]= " + novosValores[0]); 31 | System.out.println("O vetor é : posição [1]= " + novosValores[1]); 32 | System.out.println("O vetor é : posição [2]= " + novosValores[2]); 33 | System.out.println("O vetor é : posição [3]= " + novosValores[3]); 34 | System.out.println("O vetor é : posição [4]= " + novosValores[4]); 35 | } 36 | 37 | //exercícios para fazer em casa 38 | public void exercicio1() { 39 | double[] novosValores = new double[10]; 40 | novosValores[0] = 15.9; 41 | novosValores[1] = 11.2; 42 | novosValores[2] = 17.5; 43 | novosValores[3] = 25.4; 44 | novosValores[4] = 6.1; 45 | novosValores[5] = 16.8; 46 | novosValores[6] = 26.7; 47 | novosValores[7] = 36.3; 48 | novosValores[8] = 46.6; 49 | novosValores[9] = 56.2; 50 | System.out.println("O vetor é : posição [0]= " + novosValores[0]); 51 | System.out.println("O vetor é : posição [1]= " + novosValores[1]); 52 | System.out.println("O vetor é : posição [2]= " + novosValores[2]); 53 | System.out.println("O vetor é : posição [3]= " + novosValores[3]); 54 | System.out.println("O vetor é : posição [4]= " + novosValores[4]); 55 | System.out.println("O vetor é : posição [5]= " + novosValores[5]); 56 | System.out.println("O vetor é : posição [6]= " + novosValores[6]); 57 | System.out.println("O vetor é : posição [7]= " + novosValores[7]); 58 | System.out.println("O vetor é : posição [8]= " + novosValores[8]); 59 | System.out.println("O vetor é : posição [9]= " + novosValores[9]); 60 | } 61 | 62 | public void exercicio2() { 63 | System.out.println("Informe a sua nota 1:"); 64 | double notaUm = sc.nextDouble(); 65 | 66 | System.out.println("Informe a sua nota 2:"); 67 | double notaDois = sc.nextDouble(); 68 | 69 | System.out.println("Informe a sua nota 3:"); 70 | double notaTres = sc.nextDouble(); 71 | 72 | System.out.println("Informe a sua nota 4:"); 73 | double notaQuatro = sc.nextDouble(); 74 | 75 | double mediaPonderada = (notaUm + notaDois + notaTres + notaQuatro) / 2; 76 | 77 | double[] mostrarMedia = new double[4]; 78 | mostrarMedia[0] = notaUm; 79 | mostrarMedia[1] = notaDois; 80 | mostrarMedia[2] = notaTres; 81 | mostrarMedia[3] = notaQuatro; 82 | 83 | System.out.println("Sua nota 1 é : " + mostrarMedia[0]); 84 | System.out.println("Sua nota 2 é : " + mostrarMedia[1]); 85 | System.out.println("Sua nota 3 é : " + mostrarMedia[2]); 86 | System.out.println("Sua nota 4 é : " + mostrarMedia[3]); 87 | System.out.println("Sua média é : " + mediaPonderada); 88 | } 89 | 90 | // exercício extra, ler 10 valores reais e colocar eles na ordem contrária 91 | 92 | public void exercicio4() { 93 | 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /ExercicioGrupo/Exercicio.java: -------------------------------------------------------------------------------- 1 | package ExercicioGrupo; 2 | import java.util.Scanner; 3 | 4 | public class Exercicio { 5 | Scanner sc = new Scanner(System.in); 6 | public void exercicio() { 7 | 8 | System.out.println("Informe sua Altura: "); 9 | double altura = sc.nextDouble(); 10 | System.out.println("Informe seu peso:"); 11 | double peso = sc.nextDouble(); 12 | System.out.println("Informe seu sexo: 1 - feminino, 2 - masculino:"); 13 | int sexo = sc.nextInt(); 14 | System.out.println("Informe a sua idade: "); 15 | int idade = sc.nextInt(); 16 | 17 | double pesoIdeal = (peso * altura); 18 | double imc = peso / (altura * altura); 19 | 20 | 21 | 22 | switch (sexo) { 23 | case 1:{ 24 | double formulaMulher = (62.1 * altura) - 44.7; 25 | if (formulaMulher >= 20 && formulaMulher <= 27) 26 | { 27 | System.out.println("O seu peso é normal"); 28 | } 29 | 30 | else if (formulaMulher < 20) 31 | { 32 | System.out.println("Você está abaixo do peso ideal"); 33 | } 34 | else if (formulaMulher > 27) 35 | { 36 | System.out.println("Você está acima do peso"); 37 | } 38 | break; 39 | } 40 | 41 | case 2:{ 42 | double formulaHomem = (72.7 * altura) - 58; 43 | if (formulaHomem >= 20 && formulaHomem <= 27) 44 | { 45 | System.out.println("O seu peso é normal"); 46 | } 47 | 48 | else if (formulaHomem < 20) 49 | { 50 | System.out.println("Você está abaixo do peso ideal"); 51 | } 52 | else if (formulaHomem > 27) 53 | { 54 | System.out.println("Você está acima do peso"); 55 | } 56 | break; 57 | } 58 | 59 | default:{ 60 | break; 61 | } 62 | 63 | if ( (imc >= 27) && (idade >= 25 && idade <= 45) ) { 64 | System.out.println( "As atividades recomendadas são: Musculação Intensa e Luta" ); 65 | } 66 | else if ( (imc >= 27) && (idade >= 16 && idade < 25) ) { 67 | System.out.println( "A atividade recomendada é: luta" ); 68 | } 69 | else if ( (imc >= 27) && (idade >= 46 && idade <= 55) ){ 70 | System.out.println( "As atividades recomendadas são: Luta e Pilates" ); 71 | } 72 | else if ((imc > 27) && (idade >= 56)) { 73 | System.out.println( "A atividade recomendada é: Pilates" ); 74 | } 75 | else if ( (imc > 20 && imc < 27) && (idade >= 16 && idade < 25) ){ 76 | System.out.println("As atividades recomendadas são: Musculação Moderada e Dança"); 77 | } 78 | else if ( (imc > 20 && imc < 27) && (idade >= 25 && idade <= 55) ) { 79 | System.out.println("As atividades recomendadas são: Corrida, Musculação Moderada e Dança"); 80 | } 81 | else if ( (imc > 20 && imc < 27) && (idade >= 56 && idade <= 65)){ 82 | System.out.println("As atividades recomendadas são: Corrida e Dança"); 83 | } 84 | else if ((imc > 20 && imc < 27) && (idade >= 66)){ 85 | System.out.println("A atividade recomendada é: Dança"); 86 | } 87 | else if ( (imc >= 27) && (idade >= 16 && idade < 25) ) { 88 | System.out.println("As atividades recomendadas são: Musculação Leve e Yoga"); 89 | } 90 | else if ( (imc >= 27) && (idade >= 25 && idade <= 45) ) { 91 | System.out.println("A atividade recomendada é: Yoga"); 92 | } 93 | else { 94 | System.out.println("As atividades recomendadas são: Musculação Leve e Yoga"); 95 | } 96 | } 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /ProjetoFinalTestes/Banco.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalTestes; 2 | 3 | import java.util.Scanner; 4 | 5 | import javax.swing.JOptionPane; 6 | 7 | public class Banco extends Pessoa{ 8 | Scanner sc = new Scanner(System.in); 9 | public double saldo; 10 | public int codigo = 0; 11 | public String contaTipo; 12 | public int senha; 13 | 14 | public Banco(String nome, int idade, double saldo, int codigo, String contaTipo) { 15 | super(nome, idade); 16 | this.saldo = saldo; 17 | this.codigo = codigo; 18 | this.contaTipo = contaTipo; 19 | } 20 | 21 | public void criarConta() { 22 | JOptionPane.showMessageDialog(null,"Criação de Contas (Somente pessoas maiores de 18 podem criar uma conta)."); 23 | setIdade(Integer.parseInt(JOptionPane.showInputDialog("Informe sua idade: "))); 24 | 25 | if (getIdade() > 18) { 26 | int receber = Integer.parseInt(JOptionPane 27 | .showInputDialog("Escolha o tipo de conta (1 - Conta Pessoa Física; 2 - Conta Pessoa Jurídica)")); 28 | 29 | switch (receber) { 30 | case 1: { 31 | JOptionPane.showMessageDialog(null, "Criação de Conta: Pessoa Física"); 32 | setNome(JOptionPane.showInputDialog("Informe o nome da conta: ")); 33 | setSenha(Integer.parseInt(JOptionPane.showInputDialog("Informe a senha da conta (Apenas 6 digitos): "))); 34 | codigo++; 35 | setContaTipo("Conta PF"); 36 | break; 37 | } 38 | case 2: { 39 | JOptionPane.showMessageDialog(null, "Criação de Conta: Pessoa Jurídica"); 40 | setNome(JOptionPane.showInputDialog("Informe o nome da conta: ")); 41 | setSenha(Integer.parseInt(JOptionPane.showInputDialog("Informe a senha da conta (Apenas 6 digitos): "))); 42 | codigo++; 43 | setContaTipo("Conta PJ"); 44 | break; 45 | } 46 | 47 | default: 48 | JOptionPane.showMessageDialog(null, "Selecione um desses valores!"); 49 | break; 50 | } 51 | } 52 | else 53 | JOptionPane.showMessageDialog(null,"Somente adultos maiores de 18 anos podem criar conta!"); 54 | } 55 | 56 | public void exibirConta(){ 57 | /*JOptionPane.showMessageDialog(null,"Buscar Contas");*/ System.out.println("Buscar Contas"); 58 | /*String buscarNome = JOptionPane.showInputDialog("Informe o nome da conta para ser buscado:");*/ System.out.println("Informe o nome da conta para ser buscado:"); 59 | String buscarNome = sc.next(); 60 | if (buscarNome.equals(getNome())){ 61 | /*JOptionPane.showMessageDialog(null,"Nome: " + getNome()); 62 | JOptionPane.showMessageDialog(null,"Idade: " + getIdade()); 63 | JOptionPane.showMessageDialog(null,"Código: " + getCodigo()); 64 | JOptionPane.showMessageDialog(null,"Tipo da conta: " + get); 65 | JOptionPane.showMessageDialog(null,"Saldo: " + getSaldo());*/ 66 | System.out.println("Nome: " + getNome()); 67 | System.out.println("Idade: " + getIdade()); 68 | System.out.println("Código: " + getCodigo()); 69 | System.out.println("Saldo: " + getSaldo()); 70 | } 71 | else{ 72 | JOptionPane.showMessageDialog(null,"Nome não encontrado."); 73 | } 74 | 75 | } 76 | 77 | 78 | 79 | public double getSaldo() { 80 | return saldo; 81 | } 82 | 83 | public void setSaldo(double saldo) { 84 | this.saldo = saldo; 85 | } 86 | 87 | public int getCodigo() { 88 | return codigo; 89 | } 90 | 91 | public void setCodigo(int codigo) { 92 | this.codigo = codigo; 93 | } 94 | 95 | public String getContaTipo() { 96 | return contaTipo; 97 | } 98 | 99 | public void setContaTipo(String contaTipo) { 100 | this.contaTipo = contaTipo; 101 | } 102 | 103 | public int getSenha() { 104 | return senha; 105 | } 106 | 107 | public void setSenha(int senha) { 108 | this.senha = senha; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /ListaAtividadeFormativa/Exercicios.java: -------------------------------------------------------------------------------- 1 | package ListaAtividadeFormativa; 2 | import java.util.Random; 3 | import java.util.Scanner; 4 | 5 | public class Exercicios { 6 | Scanner sc = new Scanner(System.in); 7 | Random rd = new Random(); 8 | 9 | public void exercicio1() { 10 | int matriz[][]; 11 | int linha=0; 12 | int coluna=0; 13 | 14 | System.out.println("Informe a quantidade de linhas da matriz"); 15 | linha = sc.nextInt(); 16 | System.out.println("Informe a quantidade de colunas da matriz"); 17 | coluna = sc.nextInt(); 18 | 19 | matriz = new int[linha][coluna]; 20 | 21 | for (int i = 0; i < linha; i++) { 22 | for (int j = 0; j < coluna; j++) { 23 | matriz[i][j] = rd.nextInt(9); 24 | } 25 | } 26 | 27 | 28 | System.out.println("Matriz sorteada: "); 29 | 30 | for (int i = 0; i < linha; i++) { 31 | System.out.print("| "); 32 | for (int j = 0; j < coluna; j++) { 33 | System.out.print(matriz[i][j] + " "); 34 | } 35 | System.out.println("|"); 36 | } 37 | 38 | for (int i = 0; i < linha; i++) { 39 | for (int j = 0; j < coluna; j++) { 40 | if(i > j) { 41 | matriz[i][j] = 1; 42 | } 43 | else if(i == j) { 44 | matriz[i][j]=0; 45 | } 46 | else if(j > i) { 47 | matriz[i][j] = 2; 48 | } 49 | } 50 | } 51 | 52 | System.out.println("==========================================================="); 53 | System.out.println("Matriz com as condições:"); 54 | for (int i = 0; i < linha; i++) { 55 | System.out.print("| "); 56 | for (int j = 0; j < coluna; j++) { 57 | System.out.print(matriz[i][j] + " "); 58 | } 59 | System.out.println("|"); 60 | } 61 | } 62 | 63 | public void exercicio2() { 64 | int cont=1; 65 | int nSorteado; 66 | int palpite = -1; 67 | 68 | nSorteado = rd.nextInt(1000); 69 | 70 | 71 | while(palpite != nSorteado) { 72 | System.out.println("Informe o seu palpite de n° sorteado: "); 73 | palpite = sc.nextInt(); 74 | cont++; 75 | if(palpite > nSorteado) { 76 | System.out.println("O n° que você digitou é diferente do sorteado e maior do que o sorteado. Tente novamente."); 77 | } 78 | else if(palpite < nSorteado) { 79 | System.out.println("O n° que você digitou é diferente do sorteado e menor do que o sorteado. Tente novamente."); 80 | } 81 | else if(palpite == nSorteado) { 82 | System.out.println("Parabéns! Você acertou o n° sorteado."); 83 | System.out.println("O n° de tentativas até o acerto foi de: " + cont); 84 | } 85 | } 86 | } 87 | 88 | public void exercicio3() { 89 | int vetor[]; 90 | int tamanhoVetor = rd.nextInt(901) + 100; 91 | vetor = new int[tamanhoVetor]; 92 | int contadorPares=0; 93 | int contadorImpares=0; 94 | 95 | for (int i = 0; i < vetor.length; i++) { 96 | vetor[i] = rd.nextInt(100); 97 | } 98 | 99 | System.out.println("Números pares: "); 100 | 101 | for (int i = 0; i< vetor.length; i++) { 102 | if(vetor[i] % 2 == 0) { 103 | System.out.print(vetor[i] + "; "); 104 | } 105 | } 106 | System.out.println("==================================="); 107 | 108 | System.out.println("N°s ímpares: "); 109 | for (int i = 0; i < vetor.length; i++) { 110 | if(vetor[i] % 2 != 0) { 111 | System.out.print(vetor[i] + "; "); 112 | } 113 | } 114 | 115 | for (int i = 0; i < vetor.length; i++) { 116 | if(vetor[i] % 2 == 0 & i % 2 != 0){ 117 | contadorPares++; 118 | } 119 | else if(vetor[i] % 2 != 0 & i % 2 == 0 ){ 120 | contadorImpares++; 121 | } 122 | } 123 | 124 | System.out.println("==================================================================================="); 125 | 126 | System.out.println("N°s pares na posição ímpar: " + contadorPares); 127 | System.out.println("N°s ímpares na posição par: " + contadorImpares); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /ProjetoFinalSemestre/Conta.java: -------------------------------------------------------------------------------- 1 | package ProjetoFinalSemestre; 2 | 3 | import javax.swing.JOptionPane; 4 | 5 | /** 6 | * Conta 7 | */ 8 | public class Conta extends Pessoa { 9 | public double saldo; 10 | public int codigo = 0; 11 | public String contaTipo; 12 | public int senha; 13 | public double saque = 0; 14 | public double deposito = 0; 15 | public double emprestimo = 0; 16 | 17 | public void criarConta() { 18 | JOptionPane.showMessageDialog(null, "Seja bem-vindo ao banco! Aqui, iremos criar a sua conta"); 19 | setIdade(Integer.parseInt(JOptionPane.showInputDialog("Informe sua idade: "))); 20 | 21 | if (getIdade() >= 18) { 22 | int receber = Integer.parseInt(JOptionPane 23 | .showInputDialog("Escolha o tipo de conta (1 - Conta Pessoa Física; 2 - Conta Pessoa Jurídica)")); 24 | 25 | switch (receber) { 26 | case 1: { 27 | JOptionPane.showMessageDialog(null, "Criação de Conta: Pessoa Física"); 28 | setNome(JOptionPane.showInputDialog("Informe o nome da conta: ")); 29 | setSenha(Integer 30 | .parseInt(JOptionPane.showInputDialog("Informe a senha da conta (Apenas 6 digitos): "))); 31 | codigo++; 32 | setContaTipo("Conta PF"); 33 | break; 34 | } 35 | case 2: { 36 | JOptionPane.showMessageDialog(null, "Criação de Conta: Pessoa Jurídica"); 37 | setNome(JOptionPane.showInputDialog("Informe o nome da conta: ")); 38 | setSenha(Integer 39 | .parseInt(JOptionPane.showInputDialog("Informe a senha da conta (Apenas 6 digitos): "))); 40 | codigo++; 41 | setContaTipo("Conta PJ"); 42 | break; 43 | } 44 | 45 | default: 46 | JOptionPane.showMessageDialog(null, "Selecione um desses valores!"); 47 | break; 48 | } 49 | } else 50 | JOptionPane.showMessageDialog(null, "Somente adultos maiores de 18 anos podem criar conta!"); 51 | } 52 | 53 | //Método Incompleto 54 | public double saque(){ 55 | JOptionPane.showMessageDialog(null,"Método de Saques"); 56 | double saquear = Integer.parseInt(JOptionPane.showInputDialog("Selecione a quantidade de valores para saquear (Limite: 2.780):")); 57 | if(saquear > 10 && saquear < 2780) 58 | { 59 | saque += saquear; 60 | } 61 | else{ 62 | JOptionPane.showMessageDialog(null,"Valor inválido!"); 63 | } 64 | return saque; 65 | } 66 | 67 | public double emprestimo() { 68 | JOptionPane.showMessageDialog(null,"Método de Empréstimos"); 69 | double emprestar = Integer.parseInt(JOptionPane.showInputDialog("Selecione a quantidade de valores que quer pro empréstimo (Limite: 80.000):")); 70 | if(emprestar > 1000 && emprestar < 80.000) 71 | { 72 | emprestimo += emprestar; 73 | } 74 | else{ 75 | JOptionPane.showMessageDialog(null,"Valor inválido!"); 76 | } 77 | return emprestimo; 78 | } 79 | public double deposito() { 80 | double cont = 0; 81 | JOptionPane.showMessageDialog(null,"Método de Depósito"); 82 | double depositar = Integer.parseInt(JOptionPane.showInputDialog("Selecione o valor que quer depositar: (Limite: 30.000):")); 83 | if(depositar > 0 && depositar < 30.000) { 84 | deposito += depositar; 85 | } 86 | else{ 87 | JOptionPane.showMessageDialog(null,"Valor inválido!"); 88 | } 89 | cont++; 90 | return deposito; 91 | } 92 | 93 | public double getSaldo() { 94 | return saldo; 95 | } 96 | 97 | public void setSaldo(double saldo) { 98 | this.saldo = saldo; 99 | } 100 | 101 | public int getCodigo() { 102 | return codigo; 103 | } 104 | 105 | public void setCodigo(int codigo) { 106 | this.codigo = codigo; 107 | } 108 | 109 | public String getContaTipo() { 110 | return contaTipo; 111 | } 112 | 113 | public void setContaTipo(String contaTipo) { 114 | this.contaTipo = contaTipo; 115 | } 116 | 117 | public int getSenha() { 118 | return senha; 119 | } 120 | 121 | public void setSenha(int senha) { 122 | this.senha = senha; 123 | } 124 | 125 | public double getSaque() { 126 | return saque; 127 | } 128 | 129 | public void setSaque(double saque) { 130 | this.saque = saque; 131 | } 132 | 133 | public double getDeposito() { 134 | return deposito; 135 | } 136 | 137 | public void setDeposito(double deposito) { 138 | this.deposito = deposito; 139 | } 140 | 141 | public double getEmprestimo() { 142 | return emprestimo; 143 | } 144 | 145 | public void setEmprestimo(double emprestimo) { 146 | this.emprestimo = emprestimo; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /Operadores/Operadores.java: -------------------------------------------------------------------------------- 1 | package Operadores; 2 | 3 | public class Operadores { 4 | public void aritimetico() { 5 | System.out.println("==============================="); 6 | int adicao = 5 + 2; 7 | System.out.println("Resultado da adição de 5 com 2: " + adicao); 8 | int subtracao = 5 - 2; 9 | System.out.println("Resultado da subtração de 5 pelo 2: " 10 | 11 | + subtracao); 12 | int multiplicacao = 5 * 2; 13 | System.out.println("Resultado da multiplicação de 5 pelo 2: " 14 | 15 | + multiplicacao); 16 | double divisao = 5.0 / 2.0; 17 | System.out.println("Resultado da divisão de 5 pelo 2: " + divisao); 18 | double moduloOuResto = 5.0 % 2.0; 19 | System.out.println("Resto da divisão de 5 pelo 2: " 20 | 21 | + moduloOuResto); 22 | System.out.println("Fim!"); 23 | System.out.println("==============================="); 24 | } 25 | 26 | public void atribuicao() { 27 | System.out.println("==============================="); 28 | int umNumero = 5; 29 | umNumero += 2; 30 | System.out.println("Resultado da adição de 5 com 2: " + umNumero); 31 | umNumero = 5; // Voltando o valor para 5. 32 | umNumero -= 2; 33 | System.out.println("Resultado da subtração de 5 pelo 2: " 34 | 35 | + umNumero); 36 | 37 | umNumero = 5; // Voltando o valor para 5. 38 | umNumero *= 2; 39 | System.out.println("Resultado da multiplicação de 5 pelo 2: " 40 | 41 | + umNumero); 42 | 43 | umNumero = 5; // Voltando o valor para 5. 44 | umNumero /= 2; 45 | System.out.println("Resultado da divisão de 5 pelo 2: " 46 | 47 | + umNumero); 48 | 49 | umNumero = 5; // Voltando o valor para 5. 50 | umNumero %= 2; 51 | System.out.println("Resto da divisão de 5 pelo 2: " + umNumero); 52 | System.out.println("Fim!"); 53 | System.out.println("==============================="); 54 | } 55 | 56 | public void relacionais() { 57 | System.out.println("==============================="); 58 | // Faça testes alterando o valor das duas variáveis abaixo. 59 | int primeiraVariavel = 1; 60 | int segundaVariavel = 1; 61 | System.out.println("O valor da primeira variável é " 62 | + primeiraVariavel + " e o da segunda é " 63 | + segundaVariavel + "."); 64 | boolean primeiraVariavelEMaiorQueASegunda = primeiraVariavel > segundaVariavel; 65 | System.out.println("Primeira variável é maior que a segunda? " 66 | + primeiraVariavelEMaiorQueASegunda); 67 | boolean primeiraVariavelEMenorQueASegunda = primeiraVariavel < segundaVariavel; 68 | System.out.println("Primeira variável é menor que a segunda? " 69 | + primeiraVariavelEMenorQueASegunda); 70 | boolean primeiraVariavelEMaiorIgualASegunda = primeiraVariavel >= segundaVariavel; 71 | System.out.println("Primeira variável é maior ou igual a segunda? " 72 | + primeiraVariavelEMaiorIgualASegunda); 73 | boolean primeiraVariavelEMenorIgualASegunda = primeiraVariavel <= segundaVariavel; 74 | System.out.println("Primeira variável é menor ou igual a segunda? " 75 | + primeiraVariavelEMenorIgualASegunda); 76 | boolean primeiraVariavelEIgualASegunda = primeiraVariavel == segundaVariavel; 77 | System.out.println("Primeira variável é igual a segunda? " 78 | + primeiraVariavelEIgualASegunda); 79 | boolean primeiraVariavelEDiferenteDaSegunda = primeiraVariavel != segundaVariavel; 80 | System.out.println("Primeira variável é diferente da segunda? " 81 | + primeiraVariavelEDiferenteDaSegunda); 82 | System.out.println("Fim!"); 83 | System.out.println("==============================="); 84 | } 85 | 86 | public void logicos() { 87 | System.out.println("==============================="); 88 | // Faça testes alterando o valor das quatro variáveis abaixo. 89 | // Lembrando, elas podem ser true ou false. 90 | boolean usuarioVIP = true; 91 | boolean compraComValorAlto = true; 92 | boolean menorDeIdade = true; 93 | boolean temProdutoAlcoolicoNoCarrinho = true; 94 | System.out.println("Usuário é VIP? " + usuarioVIP); 95 | System.out.println("A compra tem um valor alto? " 96 | + compraComValorAlto); 97 | System.out.println("É menor de idade? " + menorDeIdade); 98 | System.out.println("Tem produto alcoólico no carrinho? " 99 | + temProdutoAlcoolicoNoCarrinho); 100 | System.out.println("==============================="); 101 | boolean aplicarDesconto = usuarioVIP && compraComValorAlto; 102 | System.out.println("O desconto deve ser aplicado? " 103 | + "(usuarioVIP && compraComValorAlto): " 104 | + aplicarDesconto); 105 | aplicarDesconto = usuarioVIP || compraComValorAlto; 106 | System.out.println("O desconto deve ser aplicado? " 107 | + "(usuarioVIP || compraComValorAlto): " 108 | + aplicarDesconto); 109 | // Leia assim: "se não for menor de idade ou se 110 | // não tiver produto alcoólico". 111 | boolean permiteConcluirCompra = !menorDeIdade || !temProdutoAlcoolicoNoCarrinho; 112 | System.out.println("Pode concluir compra? " 113 | + "(!menorDeIdade || !temProdutoAlcoolicoNoCarrinho): " 114 | + permiteConcluirCompra); 115 | System.out.println("Fim!"); 116 | System.out.println("==============================="); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Matriz/MatrizExemplo.java: -------------------------------------------------------------------------------- 1 | package Matriz; 2 | import java.util.Random; 3 | import java.util.Scanner; 4 | 5 | public class MatrizExemplo { 6 | Scanner sc = new Scanner(System.in); 7 | Random rd = new Random(); 8 | 9 | public void exemplo1() { 10 | // criar, preencher e manipular a matriz 11 | // declarar a matriz 12 | int matriz[][] = new int[10][9]; // 2 dimensões 13 | 14 | //preencher a minha matriz 15 | for (int i = 0; i < 10; i++) { 16 | for (int j = 0; j < 9; j++) { 17 | System.out.print("Matriz["+i+"]["+j+"]="); 18 | matriz[i][j] = rd.nextInt(10); 19 | } 20 | } 21 | 22 | // impressão dos elementos da minha matriz de forma individual 23 | for (int i = 0; i < 10; i++) { 24 | for (int j = 0; j < 9; j++) { 25 | System.out.println("Matriz["+i+"]["+j+"]=" + matriz[i][j]); 26 | } 27 | } 28 | 29 | // imprimir em formato de matriz 30 | for (int i = 0; i < 10; i++) { 31 | System.out.print("| "); 32 | for (int j = 0; j < 9; j++) { 33 | System.out.print(matriz[i][j]+ " "); 34 | } 35 | System.out.println("|"); 36 | } 37 | } 38 | 39 | public void exemplo2() { // somar os n°s da quarta linha da matriz 40 | // criar, preencher e manipular a matriz 41 | // declarar a matriz 42 | int matriz[][] = new int[10][9]; // 2 dimensões 43 | int soma = 0; 44 | 45 | //preencher a minha matriz 46 | for (int i = 0; i < 10; i++) { 47 | for (int j = 0; j < 9; j++) { 48 | System.out.print("Matriz["+i+"]["+j+"]="); 49 | matriz[i][j] = rd.nextInt(10); 50 | } 51 | } 52 | 53 | // impressão dos elementos da minha matriz de forma individual 54 | for (int i = 0; i < 10; i++) { 55 | for (int j = 0; j < 9; j++) { 56 | System.out.println("Matriz["+i+"]["+j+"]=" + matriz[i][j]); 57 | } 58 | } 59 | 60 | // imprimir em formato de matriz 61 | for (int i = 0; i < 10; i++) { 62 | System.out.print("| "); 63 | for (int j = 0; j < 9; j++) { 64 | System.out.print(matriz[i][j]+ " "); 65 | } 66 | System.out.println("|"); 67 | } 68 | 69 | for (int i = 0; i < 9; i++) { 70 | soma += matriz[3][i]; 71 | } 72 | System.out.println("Soma da 4° linha= " + soma); 73 | 74 | //somar os itens da 4° coluna 75 | int coluna=0; 76 | for (int i = 0; i < 10; i++) { 77 | coluna += matriz[i][3]; 78 | } 79 | 80 | System.out.println("A soma da 4° coluna é: " + coluna); 81 | } 82 | 83 | public void exercicio1() { // exercicios extras do PDF matriz 84 | int matriz[][] = new int[5][5]; 85 | for (int i = 0; i < matriz.length; i++) { 86 | for (int j = 0; j < matriz.length; j++) { 87 | if(i == j || i+j == 4){ // irá formar um X 88 | matriz[i][j] = 1; 89 | } 90 | } 91 | } 92 | 93 | for (int i = 0; i < matriz.length; i++) { 94 | System.out.print("| "); 95 | for (int j = 0; j < matriz.length; j++) { 96 | System.out.print(matriz[i][j]+ " "); 97 | } 98 | System.out.println("|"); 99 | } 100 | } 101 | 102 | public void exercicio2() { 103 | int matriz[][] = new int[4][4]; 104 | for (int i = 0; i < matriz.length; i++) { 105 | for (int j = 0; j < matriz.length; j++) { 106 | matriz[i][j] = rd.nextInt(4); 107 | } 108 | } 109 | 110 | System.out.println("Matriz normal: "); 111 | for (int i = 0; i < matriz.length; i++) { 112 | System.out.print("| "); 113 | for (int j = 0; j < matriz.length; j++) { 114 | System.out.print(matriz[i][j]+ " "); 115 | } 116 | System.out.println("|"); 117 | } 118 | 119 | System.out.println("=================="); 120 | System.out.println("Matriz transposta: "); 121 | for (int i = 0; i < matriz.length; i++) { 122 | System.out.print("| "); 123 | for (int j = 0; j < matriz.length; j++) { 124 | System.out.print(matriz[j][i]+ " "); 125 | } 126 | System.out.println("|"); 127 | } 128 | 129 | // calcular a soma dos elementos na diagonal principal 130 | int soma =0; 131 | for (int i = 0; i < matriz.length; i++) { 132 | for (int j = 0; j < matriz.length; j++) { 133 | if(i == j) { 134 | soma += matriz[i][j]; 135 | } 136 | } 137 | } 138 | 139 | System.out.println("Soma da diagonal principal: " + soma); 140 | } 141 | 142 | public void exercicio3() { // exercicio extra - fazer a soma dos n°s acima da diagonal principal e soma dos n°s abaixo da diagonal principal 143 | int matriz[][] = new int[4][4]; 144 | int somaCima =0; 145 | int somaBaixo=0; 146 | 147 | for (int i = 0; i < matriz.length; i++) { 148 | for (int j = 0; j < matriz.length; j++) { 149 | matriz[i][j] = rd.nextInt(4); 150 | } 151 | } 152 | 153 | System.out.println("Matriz normal: "); 154 | for (int i = 0; i < matriz.length; i++) { 155 | System.out.print("| "); 156 | for (int j = 0; j < matriz.length; j++) { 157 | System.out.print(matriz[i][j]+ " "); 158 | } 159 | System.out.println("|"); 160 | } 161 | 162 | // soma acima da diagonal principal 163 | for (int i = 0; i < matriz.length; i++) { 164 | for (int j = 0; j < matriz.length; j++) { 165 | if(j > i) { 166 | somaCima+= matriz[i][j]; 167 | } 168 | } 169 | } 170 | 171 | //soma abaixo da diagonal principal 172 | for (int i = 0; i < matriz.length; i++) { 173 | for (int j = 0; j < matriz.length; j++) { 174 | if(i > j) { 175 | somaBaixo+= matriz[i][j]; 176 | } 177 | } 178 | } 179 | System.out.println("Soma dos n° acima da diagonal principal: " + somaCima); 180 | System.out.println("Soma dos n° abaixo da diagonal principal: " + somaBaixo); 181 | } 182 | } 183 | 184 | -------------------------------------------------------------------------------- /ForWhileExerciciosExtras/Exercicios.java: -------------------------------------------------------------------------------- 1 | package ForWhileExerciciosExtras; 2 | 3 | import java.util.Scanner; 4 | 5 | import javax.print.attribute.standard.Media; 6 | 7 | public class Exercicios { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | public void exercicio1() { 11 | String nome, senha; 12 | boolean verdadeiro = true; 13 | 14 | System.out.println("------------------------------------------------------------------"); 15 | System.out.println(""); 16 | 17 | while(verdadeiro) { 18 | System.out.println("Digite o seu nome de usuário: "); 19 | nome = sc.next(); 20 | System.out.println("Digite a sua senha: "); 21 | senha = sc.next(); 22 | 23 | if(nome.equals(senha)) { 24 | System.out.println("O nome de usuário e a senha não podem ser iguais. Digite novamente."); 25 | } 26 | else { 27 | verdadeiro = false; 28 | System.out.println("Login concluído!"); 29 | } 30 | System.out.println("------------------------------------------------------------------"); 31 | } 32 | } 33 | 34 | public void exercicio2() { 35 | String nome; 36 | int idade = 0; 37 | double salario = 0; 38 | char sexo, estado; 39 | 40 | boolean verdadeiro = true; 41 | 42 | while(verdadeiro) { 43 | System.out.println("Seu nome: "); 44 | nome = sc.next(); 45 | if(nome.length() < 3) { 46 | System.out.println("Seu nome deve ser maior que 3 caracteres. Digite novamente."); 47 | } 48 | else{ 49 | verdadeiro = false; 50 | } 51 | } 52 | 53 | verdadeiro = true; 54 | while(verdadeiro) { 55 | System.out.println("Sua idade:"); 56 | idade = sc.nextInt(); 57 | if(idade < 0 || idade > 150) { 58 | System.out.println("Sua idade deve ser entre 0 e 150. Digite novamente."); 59 | } 60 | else { 61 | verdadeiro = false; 62 | } 63 | } 64 | 65 | verdadeiro = true; 66 | while(verdadeiro) { 67 | System.out.println("Seu salário: "); 68 | salario = sc.nextDouble(); 69 | if(salario <= 0) { 70 | System.out.println("Seu salário deve ser maior do que 0. Digite novamente."); 71 | } 72 | else { 73 | verdadeiro = false; 74 | } 75 | } 76 | 77 | verdadeiro = true; 78 | while (verdadeiro) { 79 | System.out.println("Seu sexo('f' para feminino ou 'm' para masculino): "); 80 | sexo = sc.next().toLowerCase().charAt(0); 81 | if(sexo == 'f' || sexo == 'm') { 82 | verdadeiro = false; 83 | } 84 | else { 85 | System.out.println("Caractere inválidp. Digite novamente"); 86 | } 87 | } 88 | 89 | verdadeiro = true; 90 | while (verdadeiro) { 91 | System.out.println("Seu estado civil('s' para solteiro, 'c' para casado, 'v' para viúvo ou 'd' para divorciado)"); 92 | estado = sc.next().toLowerCase().charAt(0); 93 | if (estado == 's' || estado == 'c' || estado == 'v' || estado == 'd') { 94 | verdadeiro = false; 95 | } else { 96 | System.out.println("Caractere inválido. Digite novamente."); 97 | } 98 | } 99 | } 100 | 101 | public void exercicio3() { 102 | int anos=0; 103 | double taxaA = 0.03, taxaB = 0.015; 104 | double paisA = 80000, paisB = 200000; 105 | 106 | System.out.println("================================"); 107 | System.out.println("População do país A: " + paisA + "habitantes"); 108 | System.out.println(""); 109 | System.out.println("População do país B: " + paisB + "habitantes"); 110 | System.out.println(""); 111 | System.out.println("================================"); 112 | 113 | while(paisA < paisB) { 114 | paisA = paisA + (paisA * taxaA); 115 | paisB = paisB + (paisB * taxaB); 116 | anos++; 117 | } 118 | System.out.println("================================"); 119 | System.out.println(""); 120 | System.out.println("A quantidade de anos para o país A ultrapassar o país B em n° de habitantes é: " + anos + "anos"); 121 | System.out.println(""); 122 | System.out.println("================================"); 123 | } 124 | 125 | public void exercicio4() { 126 | double paisA, paisB, taxaA, taxaB; 127 | int anos = 0; 128 | 129 | System.out.println("=================================================================="); 130 | System.out.println("Informe o total de habitantes do país A: "); 131 | paisA = sc.nextDouble(); 132 | System.out.println("Informe a taxa de crescimento do país A: "); 133 | taxaA = sc.nextDouble(); 134 | System.out.println("Informe o total de habitantes do país B: "); 135 | paisB = sc.nextDouble(); 136 | System.out.println("Informe a taxa de crescimento do país B: "); 137 | taxaB = sc.nextDouble(); 138 | System.out.println("=================================================================="); 139 | 140 | while(paisA" + paisA + "habitantes"); 149 | System.out.println("População B -->" + paisB + "habitantes"); 150 | } 151 | 152 | public void exercicio5() { 153 | double vetorNumeros[] = new double[8]; 154 | double maior=0; 155 | 156 | System.out.println("Informe 8 números para o vetor: "); 157 | 158 | for (int i = 0; i < vetorNumeros.length; i++) { 159 | System.out.println((i+1) + "° posição "); 160 | vetorNumeros[i] = sc.nextDouble(); 161 | } 162 | 163 | System.out.println("=================================="); 164 | for (int i = 0; i < vetorNumeros.length; i++) { 165 | if(vetorNumeros[i] > maior){ 166 | maior = vetorNumeros[i]; 167 | } 168 | } 169 | 170 | System.out.println("O maior n° digitado foi: " + maior); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /MatrizesExerciciosExtras/Exercicios.java: -------------------------------------------------------------------------------- 1 | package MatrizesExerciciosExtras; 2 | import java.util.Random; 3 | import java.util.Scanner; 4 | 5 | public class Exercicios { 6 | Scanner sc = new Scanner(System.in); 7 | Random rd = new Random(); 8 | 9 | public void exercicio1() { 10 | int matriz[][] = new int[4][4]; 11 | for (int i = 0; i < matriz.length; i++) { 12 | for (int j = 0; j < matriz.length; j++) { 13 | matriz[i][j] = (i+1) * (j+1); 14 | } 15 | } 16 | 17 | for (int i = 0; i < matriz.length; i++) { 18 | System.out.print("| "); 19 | for (int j = 0; j < matriz.length; j++) { 20 | System.out.print(matriz[i][j] + " "); 21 | } 22 | System.out.println("|"); 23 | } 24 | } 25 | 26 | public void exercicio2() { 27 | int matriz[][] = new int[4][4]; 28 | int maior= 0; 29 | int posI = 0; 30 | int posJ = 0; 31 | 32 | for (int i = 0; i < matriz.length; i++) { 33 | for (int j = 0; j < matriz.length; j++) { 34 | matriz[i][j] = rd.nextInt(4); 35 | } 36 | } 37 | 38 | for (int i = 0; i < matriz.length; i++) { 39 | System.out.print("| "); 40 | for (int j = 0; j < matriz.length; j++) { 41 | System.out.print(matriz[i][j] + " "); 42 | } 43 | System.out.println("|"); 44 | } 45 | 46 | for (int i = 0; i < matriz.length; i++) { 47 | for (int j = 0; j < matriz.length; j++) { 48 | if(matriz[i][j] >= maior) { 49 | maior = matriz[i][j]; 50 | posI = i; 51 | posJ = j; 52 | } 53 | } 54 | } 55 | System.out.println("O maior valor é: " + maior); 56 | System.out.println("Localizada na posição ["+ (posI+1) +"]["+ (posJ+1) +"]"); 57 | } 58 | 59 | public void exercicio3() { 60 | int matriz[][] = new int[5][5]; 61 | int x; 62 | int posI = 0; 63 | int posJ = 0; 64 | 65 | 66 | for (int i = 0; i < matriz.length; i++) { 67 | for (int j = 0; j < matriz.length; j++) { 68 | matriz[i][j] = rd.nextInt(4); 69 | } 70 | } 71 | 72 | System.out.println("Digite o valor de x: "); 73 | x = sc.nextInt(); 74 | 75 | for (int i = 0; i < matriz.length; i++) { 76 | System.out.print("| "); 77 | for (int j = 0; j < matriz.length; j++) { 78 | System.out.print(matriz[i][j] + " "); 79 | } 80 | System.out.println("|"); 81 | } 82 | 83 | for (int i = 0; i < matriz.length; i++) { 84 | for (int j = 0; j < matriz.length; j++) { 85 | if(x == matriz[i][j]) { 86 | x = matriz[i][j]; 87 | posI = i; 88 | posJ = j; 89 | 90 | } 91 | } 92 | } 93 | 94 | if (x == 0) { 95 | System.out.println("Não encontrado"); 96 | } 97 | else { 98 | System.out.println("X foi encontrado em: ["+ (posI+1) +"]["+ (posJ+1) +"]"); 99 | } 100 | 101 | } 102 | 103 | public void exercicio4() { 104 | double matriz [][] = new double[10][10]; 105 | 106 | for (int i = 0; i < matriz.length; i++) { 107 | for (int j = 0; j < matriz.length; j++) { 108 | matriz[i][j] = rd.nextInt(4); 109 | } 110 | } 111 | 112 | for (int i = 0; i < matriz.length; i++) { 113 | for (int j = 0; j < matriz.length; j++) { 114 | if(i < j) { 115 | matriz[i][j] = 2 * i + 7*j - 2; 116 | } 117 | else if (i == j) { 118 | matriz[i][j] = Math.pow(3 * i, 2) - 1; 119 | } 120 | else if(i > j) { 121 | matriz[i][j] = Math.pow(4 * i, 3) - Math.pow(5 * j, 2) + 1; 122 | } 123 | } 124 | } 125 | 126 | System.out.println("Matriz com os cálculos: "); 127 | 128 | for (int i = 0; i < matriz.length; i++) { 129 | System.out.print("| "); 130 | for (int j = 0; j < matriz.length; j++) { 131 | System.out.print(matriz[i][j] + " "); 132 | } 133 | System.out.println("|"); 134 | } 135 | } 136 | 137 | public void exercicio5() { 138 | double id = 0, maioral = 0; 139 | double[][] mat = new double[5][4]; 140 | 141 | for (int i = 0; i < 5; i++) { 142 | System.out.println("entre com a matricula/ media da prova / media dos trabalhos. do aluno "+ (i+1)); 143 | for (int j = 0; j < 4; j++) { 144 | mat[i][j] = sc.nextDouble(); 145 | if(j==2) { 146 | mat[i][j+1] =((mat[i][j]+mat[i][j-1])/2); 147 | if(mat[i][j+1]>maioral) 148 | maioral=mat[i][j+1];j++;} 149 | 150 | } 151 | } 152 | 153 | for (int i = 0; i < 5; i++) { 154 | for (int j = 0; j < 4; j++) { 155 | if (j % 4 == 0)System.out.print("\n"); 156 | System.out.print(mat[i][j]+" "); 157 | 158 | 159 | 160 | } 161 | } 162 | System.out.println("\na maior nota final: " + maioral); 163 | System.out.println(" Matrícula Responsavel: " + id); 164 | } 165 | 166 | public void exercicio6() { 167 | int A[][] = new int[3][3]; 168 | int B[][] = new int[3][3]; 169 | int C[][] = new int[3][3]; 170 | 171 | for (int i = 0; i < A.length; i++) { 172 | for (int j = 0; j < A.length; j++) { 173 | A[i][j] = rd.nextInt(4); 174 | } 175 | } 176 | 177 | for (int i = 0; i < B.length; i++) { 178 | for (int j = 0; j < B.length; j++) { 179 | B[i][j] = rd.nextInt(4); 180 | } 181 | } 182 | 183 | System.out.println("Matriz A: "); 184 | for (int i = 0; i < A.length; i++) { 185 | System.out.print("| "); 186 | for (int j = 0; j < A.length; j++) { 187 | System.out.print(A[i][j] + " "); 188 | } 189 | System.out.println("|"); 190 | } 191 | 192 | System.out.println("Matriz B: "); 193 | 194 | for (int i = 0; i < B.length; i++) { 195 | System.out.print("| "); 196 | for (int j = 0; j < B.length; j++) { 197 | System.out.print(B[i][j] + " "); 198 | } 199 | System.out.println("|"); 200 | } 201 | 202 | 203 | for (int i = 0; i < C.length; i++) { 204 | for (int j = 0; j < C[i].length; j++) { 205 | for(int k = 0; k < A[i].length; k++){ 206 | C[i][j] += A[i][k] * B[k][j]; 207 | } 208 | } 209 | } 210 | 211 | System.out.println("Matriz C: "); 212 | for (int i = 0; i < C.length; i++) { 213 | System.out.print("| "); 214 | for (int j = 0; j < C.length; j++) { 215 | System.out.print(C[i][j] + " "); 216 | } 217 | System.out.println("|"); 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /ExerciciosIfElse/Exercicios.java: -------------------------------------------------------------------------------- 1 | package ExerciciosIfElse; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Exercicios { 6 | Scanner sc = new Scanner(System.in); 7 | 8 | // exercicio 1 9 | public void exercicio1() { 10 | System.out.println("Informe o valor 1: "); 11 | double valorUm = sc.nextDouble(); 12 | System.out.println("Informe o valor 2: "); 13 | double valorDois = sc.nextDouble(); 14 | if (valorUm > valorDois) { 15 | System.out.println("O valor 1 é maior do que o valor 2"); 16 | } else if (valorDois > valorUm) { 17 | System.out.println("O valor 2 é maior do que o valor 1"); 18 | } 19 | else { 20 | System.out.println("Os números são iguais"); 21 | } 22 | } 23 | 24 | // exercicio 2 25 | public void exercicio2() { 26 | System.out.println("Informe o seu ano de nascimento: "); 27 | double anoNascimento = sc.nextDouble(); 28 | double podeVotar = 2022 - anoNascimento; 29 | if (podeVotar >= 18) { 30 | System.out.println("Você poderá votar"); 31 | } else { 32 | System.out.println("Não poderá votar"); 33 | } 34 | } 35 | 36 | // exercicio 3 37 | public void exercicio3() { 38 | System.out.println("Informe a senha para acessar o computador: "); 39 | double senhaComputador = sc.nextDouble(); 40 | if (senhaComputador == 1234) { 41 | System.out.println("ACESSO PERMITIDO"); 42 | } else { 43 | System.out.println("ACESSO NEGADO"); 44 | } 45 | } 46 | 47 | // EXERCICIO 4 48 | public void exercicio4() { 49 | System.out.println("Quantas maçãs você pegou?"); 50 | double macaPegada = sc.nextDouble(); 51 | if (macaPegada >= 12) { 52 | double total = macaPegada * 0.25; 53 | System.out.println("O valor que você pagará é " + total); 54 | } else if (macaPegada < 12) { 55 | double total = macaPegada * 0.30; 56 | System.out.println("O valor que você pagará é " + total); 57 | } 58 | } 59 | 60 | // exercicio 5 61 | public void exercicio5() { 62 | System.out.println("Informe o valor 1: "); 63 | int valorUm = sc.nextInt(); 64 | System.out.println("Informe o valor 2: "); 65 | int valorDois = sc.nextInt(); 66 | System.out.println("Informe o valor 3: "); 67 | int valorTres = sc.nextInt(); 68 | if (valorUm < valorDois && valorUm < valorTres && valorDois < valorTres) { 69 | System.out.println("A ordem crescente é " + valorUm + "," + valorDois + "," + valorTres); 70 | } else if (valorDois < valorUm && valorDois < valorTres && valorUm < valorTres) { 71 | System.out.println("A ordem crescente é " + valorDois + "," + valorUm + "," + valorTres); 72 | } else if (valorTres < valorUm && valorTres < valorDois && valorUm > valorDois) { 73 | System.out.println("A ordem crescente é " + valorTres + "," + valorDois + "," + valorUm); 74 | } else if (valorUm < valorDois && valorUm < valorTres && valorDois > valorTres) { 75 | System.out.println("A ordem crescente é " + valorUm + "," + valorTres + "," + valorDois); 76 | } else if (valorDois < valorUm && valorDois < valorTres && valorTres < valorUm) { 77 | System.out.println("A ordem crescente é " + valorDois + "," + valorTres + "," + valorUm); 78 | } else if (valorTres < valorUm && valorTres < valorDois && valorDois > valorUm) { 79 | System.out.println("A ordem crescente é " + valorTres + "," + valorUm + "," + valorDois); 80 | } 81 | } 82 | 83 | // exercicio 6 84 | public void exercicio6() { 85 | System.out.println("Informe a sua altura"); 86 | double altura = sc.nextDouble(); 87 | System.out.println("Informe o seu sexo. Digite 1 se for homem e 2 se for mulher."); 88 | int sexo = sc.nextInt(); 89 | if (sexo == 1) { 90 | double formulaHomem = (72.7 * altura) - 58; 91 | System.out.println("O seu peso ideal é " + formulaHomem); 92 | } else if (sexo == 2) { 93 | double formulaMulher = (62.1 * altura) - 44.7; 94 | System.out.println("O seu peso ideal é " + formulaMulher); 95 | } 96 | } 97 | 98 | public void nota() { 99 | System.out.println("Informe a nota 1 (de 0 a 100): "); 100 | int notaUm = sc.nextInt(); 101 | System.out.println("Informe a nota 2 (de 0 a 100): "); 102 | int notaDois = sc.nextInt(); 103 | double médiaPonderada = (notaUm + notaDois) / 2; 104 | System.out.println("Informe sua frequência nas aulas, de 0 a 100: "); 105 | int frequencia = sc.nextInt(); 106 | if (médiaPonderada >= 50 && frequencia >= 75) { 107 | System.out.println("Parabéns! Você passou de ano."); 108 | } else if (médiaPonderada <= 50 && frequencia >= 75 || médiaPonderada >= 50 && frequencia <= 50 109 | || médiaPonderada <= 50 && frequencia <= 75) { 110 | System.out.println("Essa não! Você reprovou de ano."); 111 | } 112 | } 113 | 114 | // exercicios extras 115 | public void exercicio7() { 116 | System.out.println("Informe um valor inteiro: "); 117 | int valor = sc.nextInt(); 118 | if (valor % 2 == 0) { 119 | System.out.println("O número " + valor + " é par!"); 120 | } else { 121 | System.out.println("O número " + valor + " é ímpar!"); 122 | } 123 | } 124 | 125 | public void exercicio8() { 126 | System.out.println("Informe sua nota de matemática: "); 127 | double notaMat = sc.nextDouble(); 128 | System.out.println("Informe sua nota de física: "); 129 | double notaFisica = sc.nextDouble(); 130 | double média = (notaFisica + notaMat) / 2; 131 | if (média >= 7) { 132 | System.out.println("Parabéns! Sua média foi " + média + " e com isso você passou de ano."); 133 | } else if (média >= 5 && média < 7) { 134 | System.out.println("Sua média foi " + média + "." 135 | + " Caso queira, você poderá fazer uma prova de recuperação para aumentar a sua nota"); 136 | } else if (média < 5) { 137 | System.out.println("Sua média foi " + média + "." + " Com isso, você reprovou de ano."); 138 | } 139 | 140 | } 141 | 142 | public void exercicio9() { 143 | System.out.println("Digite uma letra: "); 144 | String N = sc.next(); 145 | 146 | if (N.equalsIgnoreCase("a") || N.equalsIgnoreCase("e") || N.equalsIgnoreCase("i") || N.equalsIgnoreCase("o") 147 | || N.equalsIgnoreCase("u")) { 148 | System.out.println("A letra digitada é vogal"); 149 | } else { 150 | System.out.println("A letra digitada é consoante"); 151 | } 152 | } 153 | 154 | public void exercicio10() { 155 | System.out.println("Informe o seu salário: "); 156 | double salario = sc.nextDouble(); 157 | 158 | if (salario <= 1280) { 159 | System.out.println("Salário antes do reajuste: " + salario 160 | + "\nPercentual aplicado: 20%\nValor do aumento do salário: R$" + (salario * 0.2) 161 | + "\nNovo salário, após aumento: R$" + (salario * 1.2)); 162 | } 163 | 164 | else if (salario > 1280 && salario <= 1700) { 165 | System.out.println("Salário antes do reajuste: " + salario 166 | + "\nPercentual aplicado: 20%\nValor do aumento do salário: R$" + (salario * 0.15) 167 | + "\nNovo salário, após aumento: R$" + (salario * 1.15)); 168 | } 169 | 170 | else if (salario > 1700 && salario <= 2500) { 171 | System.out.println("Salário antes do reajuste: " + salario 172 | + "\nPercentual aplicado: 20%\nValor do aumento do salário: R$" + (salario * 0.10) 173 | + "\nNovo salário, após aumento: R$" + (salario * 1.10)); 174 | } else if (salario > 2500) { 175 | System.out.println("Salário antes do reajuste: " + salario 176 | + "\nPercentual aplicado: 20%\nValor do aumento do salário: R$" + (salario * 0.05) 177 | + "\nNovo salário, após aumento: R$" + (salario * 1.05)); 178 | } 179 | } 180 | } 181 | 182 | 183 | /** 184 | * 185 | */ 186 | 187 | 188 | -------------------------------------------------------------------------------- /IteracaoFor/ExemploFor.java: -------------------------------------------------------------------------------- 1 | package IteracaoFor; 2 | 3 | import java.util.Scanner; 4 | 5 | import javax.print.attribute.standard.Media; 6 | 7 | public class ExemploFor { 8 | Scanner sc = new Scanner(System.in); 9 | 10 | public void exemplo1() { 11 | for(int i=0; i<10; i++) { 12 | System.out.println("O nº da iteração é " + i); 13 | } 14 | } 15 | 16 | public void exemplo2() { 17 | double carrinhoCompra[] = new double[] {25.69, 50.4, 86.3, 91,1}; 18 | double valorFinalCompra = 0; 19 | for (int i = 0; i < carrinhoCompra.length; i++) { 20 | valorFinalCompra += carrinhoCompra[i]; 21 | System.out.println("Valor parcial da compra R$" + valorFinalCompra); 22 | } 23 | System.out.println("O valor da compra é R$" + valorFinalCompra); 24 | } 25 | 26 | public void exercicio1() { 27 | int vetorA[] = new int[5]; 28 | 29 | for (int i = 0; i < vetorA.length; i++) { 30 | System.out.println("vetor["+i+"]="); 31 | vetorA[i] = sc.nextInt(); 32 | } 33 | System.out.println("=================="); 34 | for (int i = 0; i < vetorA.length; i++) { 35 | System.out.println("vetor["+i+"]=" +vetorA[i]); 36 | } 37 | } 38 | 39 | public void exercicio2() { 40 | double vetorA[] = new double [10]; 41 | 42 | for (int i = 0; i < vetorA.length; i++) { 43 | System.out.println("vetor["+i+"]="); 44 | vetorA[i] = sc.nextInt(); 45 | } 46 | for (int i = vetorA.length - 1; i>=0; i--) { 47 | System.out.println("vetor["+i+"]=" +vetorA[i]); 48 | } 49 | } 50 | 51 | public void exercicio3() { 52 | double vetorA[] = new double [4]; 53 | double media; 54 | 55 | for (int i = 0; i < vetorA.length; i++) { 56 | System.out.println("Nota["+i+"]="); 57 | vetorA[i] = sc.nextInt(); 58 | } 59 | 60 | media = (vetorA[0] + vetorA[1] + vetorA[2] + vetorA[3]) / 4; 61 | System.out.println("=============="); 62 | System.out.println("Sua média é:" + media); 63 | } 64 | 65 | public void exercicio4() { 66 | //criar um vetor de 10 caracteres 67 | String letras[] = new String[] {"a", "b", "c", "d", "e", "f", "g", "h", "j", "k"}; 68 | 69 | //percorrer o vetor para achar as consoantes 70 | int contador=0; // contador para as consoantes 71 | for (int i = 0; i < letras.length; i++) { 72 | //tomada de decisão: vogal ou consoante 73 | if(letras[i]!="a" && letras[i]!="e" && letras[i]!="i" && letras[i]!="o" && letras[i]!="u") { 74 | System.out.println(letras[i] + "é consoante"); 75 | contador++; 76 | } 77 | // mostrar o n° de consoantes 78 | System.out.println("O n° de consoantes é: " + contador); 79 | } 80 | } 81 | 82 | // exercicio 4 extra - lendo as consoantes de uma palavra 83 | public void exercicio4Ex() { 84 | // usuário vai digitar uma palavra 85 | System.out.println("Digite uma palavra: "); 86 | String letras = sc.next(); 87 | letras = letras.toLowerCase(); // deixar tudo em minúsculo 88 | 89 | int contador=0; 90 | for (int i = 0; i < letras.length(); i++) { 91 | char c = letras.charAt(i); 92 | if(c !='a' && c !='e' && c !='i' && c!='o' && c!='u') { 93 | System.out.println(c + " é consoante"); 94 | contador++; 95 | } 96 | 97 | } 98 | } 99 | 100 | public void exercicio5() { // 20 n°s e determinar os pares e ímpares em outros vetores 101 | int vetorNumeros[] = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; 102 | int contPar=0; 103 | int contImpar=0; 104 | // percorrer o meu vetor e contar os meus n° pares e ímpares 105 | for (int i = 0; i < vetorNumeros.length; i++) { 106 | if(vetorNumeros[i]%2 == 0) { 107 | contPar++; 108 | } else { 109 | contImpar++; 110 | } 111 | } 112 | int nPar[] = new int[contPar]; 113 | int nImpar[] = new int[contImpar]; 114 | // distribuir os n° nos vetores par e impar 115 | contPar=0; 116 | contImpar=0; 117 | for (int i = 0; i < vetorNumeros.length; i++) { 118 | if(vetorNumeros[i] % 2==0) { 119 | nPar[contPar] = vetorNumeros[i]; 120 | contPar++; 121 | } 122 | else { 123 | nImpar[contImpar] = vetorNumeros[i]; 124 | contImpar++; 125 | } 126 | } 127 | 128 | for (int i = 0; i < vetorNumeros.length; i++) { 129 | System.out.println("vetor["+i+"]=" + vetorNumeros[i]); 130 | } 131 | for (int i = 0; i < nPar.length; i++) { 132 | System.out.println("vetor["+i+"]=" + nPar[i]); 133 | } 134 | for (int i = 0; i < nImpar.length; i++) { 135 | System.out.println("vetor["+i+"]=" + nImpar[i]); 136 | } 137 | } 138 | 139 | public void exercicio6() { 140 | double[] alunos = new double[10]; 141 | double[] notas = new double[4]; 142 | int cont = 0; 143 | 144 | for (int i = 0; i < notas.length; i++) { 145 | for (int j = 0; j < notas.length; j++) { 146 | System.out.println("Digite a nota "+(j+1)+" do aluno "+ (i+1) + ":"); 147 | notas[i] = sc.nextDouble(); 148 | alunos[i] += notas[j]; 149 | } 150 | alunos[i] /= notas.length; 151 | 152 | if (notas[i] >= 7) { 153 | cont++; 154 | } 155 | } 156 | System.out.println("N° de alunos com média maior ou igual a 7: " + cont); 157 | System.out.println(""); 158 | for (int i = 0; i < alunos.length; i++) { 159 | System.out.println("A média do aluno "+(i+1)+" é"+ alunos[i]); 160 | } 161 | System.out.println(""); 162 | } 163 | 164 | public void exercicio7() { 165 | int[] vetorA = new int[5]; 166 | int[] totalSoma = new int[5]; 167 | int[] totalMult = new int[5]; 168 | 169 | for (int i = 0; i < vetorA.length; i++) { 170 | System.out.println("Informe o número " + (i+1) + ":"); 171 | vetorA[i] = sc.nextInt(); 172 | } 173 | 174 | for (int i = 0; i < totalSoma.length; i++) { 175 | totalSoma[i] = vetorA[i] + vetorA[i]; 176 | } 177 | 178 | for (int i = 0; i < totalMult.length; i++) { 179 | totalMult[i] = vetorA[i] * vetorA[i]; 180 | } 181 | System.out.println("Os valores que você informou: "); 182 | 183 | for (int i = 0; i < vetorA.length; i++) { 184 | System.out.println((i+1) + "º: " + vetorA[i]); 185 | } 186 | 187 | System.out.println("A soma dos vetores: "); 188 | for (int i = 0; i < vetorA.length; i++) { 189 | System.out.println((i+1) + "º: " + totalSoma[i]); 190 | } 191 | 192 | System.out.println("A multiplicação dos vetores "); 193 | for (int i = 0; i < vetorA.length; i++) { 194 | System.out.println((i+1) + "º: " + totalMult[i]); 195 | } 196 | } 197 | 198 | public void exercicio8() { 199 | int vetorPessoas[] = new int[5]; 200 | double altura[] = new double[5]; 201 | int idade[] = new int[5]; 202 | 203 | for (int i = 0; i < vetorPessoas.length; i++) { 204 | System.out.println("Digite a idade da pessoa " + (i+1) + ":"); 205 | idade[i] = sc.nextInt(); 206 | System.out.println("Informe a altura da pessoa " + (i+1) + ":"); 207 | altura[i] = sc.nextDouble(); 208 | } 209 | } 210 | 211 | public void exercicio9() { 212 | int[] vetor = new int[10]; 213 | int[] vetorQuad = new int[10]; 214 | int[] vetorTotal = new int[10]; 215 | int j=0; 216 | 217 | for (int i = 0; i < vetor.length; i++) { 218 | System.out.println("Informe para o vetor de índice " + (i+1) + ":"); 219 | vetor[i] = sc.nextInt(); 220 | } 221 | 222 | for (int i = 0; i < vetor.length; i++) { 223 | vetorQuad[i] = (int) Math.pow(vetor[i], 2); 224 | } 225 | for (int i = 0; i < vetor.length; i++) { 226 | vetorTotal[i] = vetorQuad[i] + vetorQuad[i]; 227 | } 228 | 229 | System.out.println("A soma dos quadrados para cada elemento será: "); 230 | for (int i = 0; i < vetor.length; i++) { 231 | j++; 232 | System.out.println(j + "° " + vetorTotal[i]); 233 | } 234 | } 235 | } 236 | 237 | --------------------------------------------------------------------------------