Notice: Undefined offset: 16534571 in /var/www/html/qa-external/qa-external-users.php on line 744
Fazer um programa em Java para a geração e a validação de senhas utilizando a técnica de encampsulamento. - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Fazer um programa em Java para a geração e a validação de senhas utilizando a técnica de encampsulamento.

+8 votes
asked Apr 4, 2020 by Alice (200 points)
Fazer um programa em Java para a geração e a validação de senhas utilizando a técnica de encampsulamento.

PS: o programa deve estar sintaticamente e semanticamente correto.

1 Answer

+1 vote
answered Dec 10, 2025 by Jien Junior (160 points)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        Senha senha = new Senha();

        System.out.println("===== SISTEMA DE SENHAS =====");
        System.out.println("1 - Gerar senha automaticamente");
        System.out.println("2 - Validar e definir senha manualmente");
        System.out.print("Escolha uma opção: ");

        int opcao = input.nextInt();
        input.nextLine(); // limpar buffer

        if (opcao == 1) {
            System.out.print("Informe o tamanho desejado da senha: ");
            int tam = input.nextInt();
            senha.gerarSenha(tam);
            System.out.println("Senha gerada: " + senha.getSenha());

        } else if (opcao == 2) {
            System.out.print("Digite a nova senha: ");
            String novaSenha = input.nextLine();
            senha.setSenha(novaSenha);

            if (!senha.getSenha().equals("")) {
                System.out.println("Senha definida com sucesso!");
            }

        } else {
            System.out.println("Opção inválida.");
        }

        input.close();
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...