//
// Created by Julio Tentor <[email protected]>
//
public class CasoEjemplo_b {
public void Run() {
ILinkedList<Character> orignalList = getData();
System.out.println("Lista original.:" + orignalList.toString());
ILinkedList<Character> uppercaseList = new SimpleLinkedList<Character>();
for (Character ch; orignalList.size() > 0; ) {
ch = orignalList.removeFirst();
if (Character.isLowerCase(ch)) {
uppercaseList.addLast(Character.toUpperCase(ch));
} else {
uppercaseList.addLast(ch);
}
}
System.out.println("Lista procesada:" + uppercaseList.toString());
}
private ILinkedList<Character> getData() {
Integer option;
while (true) {
System.out.println(
"\nTrabajo Práctico Nº 4 - Caso Ejempo b)\n" +
"\nOpciones" +
"\n 1. Ingresa valores por consola" +
"\n 2. Genera valores aleatorios"
);
option = Helper.getInteger("\nSu opción: ");
switch (option) {
case 1:
return consoleInput();
case 2:
return randomGenerate();
}
}
}
private ILinkedList<Character> consoleInput() {
ILinkedList<Character> list = new SimpleLinkedList<Character>();
Character ch;
while (true) {
ch = Helper.getCharacter("Ingrese una letra (@ para finalizar): ");
if (ch.equals('@')) {
break;
}
list.addLast(ch);
}
return list;
}
private ILinkedList<Character> randomGenerate() {
ILinkedList<Character> list = new SimpleLinkedList<Character>();
String characters = "ABCDEFGHIJKLMNÑOPRSTUVWXYZabcdefghijklmnñoprstuvwxyz";
for (int count = Helper.random.nextInt(20) + 1; count > 0; --count) {
list.addLast(characters.charAt(Helper.random.nextInt(characters.length())));
}
return list;
}
}
Comments