Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package detector_palavão;
- import javax.swing.JOptionPane;
- /**
- *
- * @author ylloluis
- */
- public class main {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int tamanho = 3;
- CriarVetor(tamanho);
- }
- public static String[] CriarVetor(int tamanho) {
- String[] palavroes = new String[tamanho];
- palavroes[0] = "porra";
- palavroes[1] = "cu";
- palavroes[2] = "puta";
- ObterFrase(palavroes);
- return palavroes;
- }
- public static String ObterFrase(String[] palavroes) {
- String frase = JOptionPane.showInputDialog(null, "Digite a sua frase: ", "Detector de palavrões", JOptionPane.PLAIN_MESSAGE);
- int confirm = JOptionPane.showConfirmDialog(null, "Esta é a frase correta? \n" + frase, "Detector de palavrões", JOptionPane.YES_NO_OPTION);
- if(confirm == JOptionPane.NO_OPTION) {
- ObterFrase(palavroes);
- } else if(confirm == JOptionPane.YES_OPTION) {
- frase = frase.toLowerCase();
- Verificar_Frase(frase, palavroes);
- } else {
- JOptionPane.showMessageDialog(null, "Opção invalida", "Detector de palavrões", JOptionPane.ERROR_MESSAGE);
- System.exit(confirm);
- }
- return frase;
- }
- public static void Verificar_Frase(String frase, String[] palavroes) {
- boolean pal_true = false;
- for (int i = 0; i < frase.length(); i++) {
- String teste = frase.substring(i, i+5);
- System.out.println(teste);
- if(frase.substring(i, i+5).equals(palavroes[i])) {
- pal_true = true;
- } else if(frase.substring(i, i+4).equals(palavroes[i])) {
- pal_true = true;
- } else if(frase.substring(i, i+2).equals(palavroes[i])) {
- pal_true = true;
- }
- }
- if(pal_true == true) {
- JOptionPane.showMessageDialog(null, "Palavrão detectado", "Detector de Palavrões", JOptionPane.ERROR_MESSAGE);
- } else {
- JOptionPane.showMessageDialog(null, "Nenhum palavrão não foi detectado", "Detector de Palavrões", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement