Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package detector_palavão;
  7.  
  8. import javax.swing.JOptionPane;
  9. /**
  10. *
  11. * @author ylloluis
  12. */
  13. public class main {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. int tamanho = 3;
  20. CriarVetor(tamanho);
  21. }
  22.  
  23. public static String[] CriarVetor(int tamanho) {
  24. String[] palavroes = new String[tamanho];
  25. palavroes[0] = "porra";
  26. palavroes[1] = "cu";
  27. palavroes[2] = "puta";
  28. ObterFrase(palavroes);
  29. return palavroes;
  30. }
  31.  
  32. public static String ObterFrase(String[] palavroes) {
  33. String frase = JOptionPane.showInputDialog(null, "Digite a sua frase: ", "Detector de palavrões", JOptionPane.PLAIN_MESSAGE);
  34. int confirm = JOptionPane.showConfirmDialog(null, "Esta é a frase correta? \n" + frase, "Detector de palavrões", JOptionPane.YES_NO_OPTION);
  35. if(confirm == JOptionPane.NO_OPTION) {
  36. ObterFrase(palavroes);
  37. } else if(confirm == JOptionPane.YES_OPTION) {
  38. frase = frase.toLowerCase();
  39. Verificar_Frase(frase, palavroes);
  40. } else {
  41. JOptionPane.showMessageDialog(null, "Opção invalida", "Detector de palavrões", JOptionPane.ERROR_MESSAGE);
  42. System.exit(confirm);
  43. }
  44. return frase;
  45. }
  46.  
  47. public static void Verificar_Frase(String frase, String[] palavroes) {
  48. boolean pal_true = false;
  49. for (int i = 0; i < frase.length(); i++) {
  50. String teste = frase.substring(i, i+5);
  51. System.out.println(teste);
  52. if(frase.substring(i, i+5).equals(palavroes[i])) {
  53. pal_true = true;
  54. } else if(frase.substring(i, i+4).equals(palavroes[i])) {
  55. pal_true = true;
  56. } else if(frase.substring(i, i+2).equals(palavroes[i])) {
  57. pal_true = true;
  58. }
  59. }
  60. if(pal_true == true) {
  61. JOptionPane.showMessageDialog(null, "Palavrão detectado", "Detector de Palavrões", JOptionPane.ERROR_MESSAGE);
  62. } else {
  63. JOptionPane.showMessageDialog(null, "Nenhum palavrão não foi detectado", "Detector de Palavrões", JOptionPane.ERROR_MESSAGE);
  64. }
  65. }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement