-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblema25.java
More file actions
50 lines (34 loc) · 1.64 KB
/
Copy pathProblema25.java
File metadata and controls
50 lines (34 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import acm.program.CommandLineProgram;
import java.util.StringTokenizer;
//HACERLO CON BUILDER [UNION MEDIANTE .append]
public class Problema25 extends CommandLineProgram {
public void run() { //[PASOS BASICOS DE UN VOID]
String frase = readLine("Introduce palabra:"); //FRASE [DAME LOS DATOS]
String resultAcro = makeAcronym(frase);//[PROCESO LOS DATOS]
println(resultAcro); // [MUESTRO LOS DATOS]
}
public String makeAcronym(String frase) {
String acronym = "";
StringTokenizer palabra = new StringTokenizer(frase);
while (palabra.hasMoreTokens()) {
String actualPalabra = palabra.nextToken();
if (check(actualPalabra)) { //se puede usar el isValid(actualPalabra)
acronym += (actualPalabra.toUpperCase().charAt(0)+'.');
//toUpperCase es estatico porque no hace falta que crea una nueva c pero en mayus sino que aplico la transformacion en la misma c
}
}
return acronym.toString(); // .substring(0, acronym.length() - 1) //hubiera servido pa descartar el punto final
}
public boolean check(String actualPalabra) { //isValid
String[] conectores = {"el", "la", "un", "una", "unos", "y", "o", "de"};
for (int i = 0; i < conectores.length; i++) {
if (actualPalabra.equalsIgnoreCase(conectores[i])) {
return false; //[isVALID] return true?????'
}
}
return true; //[isVALID] return false???????
}
public static void main(String[] args) {
new Problema25().start(args);
}
}