Created
December 23, 2016 14:57
-
-
Save LucasAlfare/0b85fa8670db0b47c3e5af3a3837feab to your computer and use it in GitHub Desktop.
Ja pensou vc vai escrever a palavra AMIGO e de repente PLAU! erra e escreve "RATUTO"? ;)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import java.util.ArrayList; | |
import java.util.Random; | |
/** | |
* Created by Lucas Sousa on 22/12/16. | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println(new Gerador().getRandomWrongAMIGO()); | |
} | |
/* | |
CLASSE INTERNA que vai gerar as palavras erradas... | |
*/ | |
private static class Gerador { | |
/* | |
Listas para armazenar vogais e consoantes | |
*/ | |
ArrayList<String> vogais = new ArrayList<>(), consoantes = new ArrayList<>(); | |
public Gerador(){ | |
/* | |
LOOP pra encher as listas com vogais OU consoantes | |
*/ | |
for (int i = 97; i < 122 + 1; i++){ | |
/* | |
SE o caractere atual for uma VOGAL... | |
*/ | |
if (isVogal((char)i)){ | |
vogais.add("" + (char)i); | |
} else { | |
/* | |
SE o caractere atual for uma CONSOANTE... | |
*/ | |
if (!( | |
/* | |
caso o caractere atual n seja nenhuma dessas consoantes... | |
*/ | |
(char)i == 'x' || | |
(char)i == 'w' || | |
(char)i == 'q' || | |
(char)i == 'h' || | |
(char)i == 'y' || | |
(char)i == 'k')){ | |
consoantes.add("" + (char)i); | |
} | |
} | |
} | |
} | |
/* | |
Junta 3 silabas aleatorias para formar um trissilabo | |
*/ | |
public String getRandomWrongAMIGO(){ | |
return getRandomSilaba() + getRandomSilaba() + getRandomSilaba(); | |
} | |
/* | |
Junta 1 consoante com 1 vogal aleatorios formando uma silaba | |
*/ | |
private String getRandomSilaba(){ | |
Random r = new Random(); | |
return consoantes.get(r.nextInt(consoantes.size())) + vogais.get(r.nextInt(vogais.size())); | |
} | |
/* | |
Indica se um caractere X e vogal ou nao | |
*/ | |
private boolean isVogal(char x){ | |
return x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment