Advertisement
jtentor

LinkedList 1er parte - CasoEjemplo_b.java

Oct 17th, 2020
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. //
  2. // Created by Julio Tentor <jtentor@fi.unju.edu.ar>
  3. //
  4.  
  5.  
  6. public class CasoEjemplo_b {
  7.  
  8.     public void Run() {
  9.         ILinkedList<Character> orignalList = getData();
  10.  
  11.         System.out.println("Lista original.:" + orignalList.toString());
  12.  
  13.         ILinkedList<Character> uppercaseList = new SimpleLinkedList<Character>();
  14.  
  15.         for (Character ch; orignalList.size() > 0; ) {
  16.             ch = orignalList.removeFirst();
  17.             if (Character.isLowerCase(ch)) {
  18.                 uppercaseList.addLast(Character.toUpperCase(ch));
  19.             } else {
  20.                 uppercaseList.addLast(ch);
  21.             }
  22.         }
  23.  
  24.         System.out.println("Lista procesada:" + uppercaseList.toString());
  25.  
  26.     }
  27.  
  28.  
  29.     private ILinkedList<Character> getData() {
  30.  
  31.         Integer option;
  32.         while (true) {
  33.             System.out.println(
  34.                     "\nTrabajo Práctico Nº 4 - Caso Ejempo b)\n" +
  35.                             "\nOpciones" +
  36.                             "\n 1. Ingresa valores por consola" +
  37.                             "\n 2. Genera valores aleatorios"
  38.             );
  39.             option = Helper.getInteger("\nSu opción: ");
  40.  
  41.             switch (option) {
  42.                 case 1:
  43.                     return consoleInput();
  44.                 case 2:
  45.                     return randomGenerate();
  46.             }
  47.         }
  48.     }
  49.  
  50.     private ILinkedList<Character> consoleInput() {
  51.         ILinkedList<Character> list = new SimpleLinkedList<Character>();
  52.  
  53.         Character ch;
  54.         while (true) {
  55.             ch = Helper.getCharacter("Ingrese una letra (@ para finalizar): ");
  56.             if (ch.equals('@')) {
  57.                 break;
  58.             }
  59.             list.addLast(ch);
  60.         }
  61.         return list;
  62.     }
  63.  
  64.     private ILinkedList<Character> randomGenerate() {
  65.         ILinkedList<Character> list = new SimpleLinkedList<Character>();
  66.         String characters = "ABCDEFGHIJKLMNÑOPRSTUVWXYZabcdefghijklmnñoprstuvwxyz";
  67.         for (int count = Helper.random.nextInt(20) + 1; count > 0; --count) {
  68.             list.addLast(characters.charAt(Helper.random.nextInt(characters.length())));
  69.         }
  70.         return list;
  71.     }
  72.  
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement