Last active
July 21, 2022 14:42
-
-
Save rdiego26/8446971 to your computer and use it in GitHub Desktop.
Desafio 1 - WDEV: Um dos serviços mais utilizados pelos usuários de aparelhos celulares é o SMS (Short Message Service), que permite o envio de mensagens curtas (até 255 caracteres em redes GSM e 160 caracteres em redes CDMA).
Para digitar uma mensagem em um aparelho que não possui um teclado QWERTY embutido é necessário fazer algumas combinaçõe…
This file contains 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
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package teclado_qwerty; | |
import java.util.HashMap; | |
/** | |
* | |
* @author ramos | |
*/ | |
public class Palavra { | |
private String texto; | |
private HashMap<String, String> charMap; | |
public Palavra(String str) { | |
this.texto = str.toUpperCase(); | |
} | |
/** | |
* Initialize char Map | |
*/ | |
private void initCharMap() { | |
charMap = new HashMap<>(); | |
charMap.put("2", "A"); | |
charMap.put("B", "2"); | |
charMap.put("C", "2"); | |
charMap.put("D", "3"); | |
charMap.put("E", "3"); | |
charMap.put("F", "3"); | |
charMap.put("G", "4"); | |
charMap.put("H", "4"); | |
charMap.put("I", "4"); | |
charMap.put("J", "5"); | |
charMap.put("K", "5"); | |
charMap.put("L", "5"); | |
charMap.put("M", "6"); | |
charMap.put("N", "6"); | |
charMap.put("O", "6"); | |
charMap.put("P", "7"); | |
charMap.put("Q", "7"); | |
charMap.put("R", "7"); | |
charMap.put("S", "7"); | |
charMap.put("T", "8"); | |
charMap.put("U", "8"); | |
charMap.put("V", "8"); | |
charMap.put("W", "3"); | |
charMap.put("X", "3"); | |
charMap.put("Y", "3"); | |
charMap.put("Z", "3"); | |
charMap.put(" ", "0"); | |
} | |
/** | |
* Recebe string e faz o parseamento | |
* @param str | |
* @return str parsed | |
*/ | |
public String parseString(String str) { | |
StringBuilder result = new StringBuilder(); | |
initCharMap(); | |
for(int j=0; j < str.length(); j++) { | |
String letra = String.valueOf(str.charAt(j)); | |
for(int i=0; i < charMap.size(); i++) { | |
if(!charMap.get(letra).isEmpty()) { | |
result.append(charMap.get(letra)); | |
break; | |
} | |
} | |
} | |
return result.toString(); | |
} | |
} |
This file contains 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 teclado_qwerty; | |
/** | |
* | |
* @author ramos | |
*/ | |
public class Principal { | |
/** | |
* | |
*/ | |
private static void banner() { | |
System.out.println("Uso: java -jar Teclado_QWERTY.jar TEXTO"); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
if(args.length == 0) { | |
banner(); | |
} else { | |
StringBuilder retorno = new StringBuilder(); | |
for(String arg : args) { | |
Palavra p = new Palavra(arg); | |
retorno.append(p.parseString(arg)); | |
} | |
System.out.println("Resultado: " + retorno.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment