how to take specific values through hashmap

Asked

Viewed 72 times

1

Guys, I have this code. What he does: it serves to count how many seconds it takes me to type a sentence, in this case, 'technology'. However, as the intention is to imitate a keyboard, this keyboard will block some letters that our dictionary does not have to be together, or rather, it does not have to form a word. For example, when typing 'Z', it is super logical that the keyboard has to lock the letter 'B', since it will be difficult to find a word that after 'Z' comes 'B''.

In the case of the code is the word 'TECHNOLOGY' and this keyboard should lock some keys for each specific letter and consequently not "pass" these blocked letters. For example: when typing the letter’T' Only the letters A,C,E,H,I,O,P,R,S,U,V,W should be left "active", or rather countable. To letter 'E': all letters shall be active; To letter 'C': only the letters A,C,E,F, H,I,K,L,,M,N,O,S,T,U shall be left "active"; To letter 'N': only the letters A,E,I,O shall be left "active"; To letter 'O': only the letters C,O,L,P,R shall be left "active"; To letter 'L': only the letters:O shall be left "active"; To letter 'O': only the letters:G shall be left "active"; To letter 'G': only the letters:I shall be left "active"; To letter 'I': only the letters "active" shall be left:A;

I would like to know how it can be implemented or if it is possible to implement, if it is possible to do this count!?

import java.util.HashMap;

public class ContagemAutoComplete {

public static void main(String[] args) {
    HashMap<String, Integer> hashLetras=new HashMap<String, Integer>();

    hashLetras.put("A", 2); hashLetras.put("B", 3); hashLetras.put("C", 4); hashLetras.put("D", 5); hashLetras.put("E", 3);

    hashLetras.put("F", 4); hashLetras.put("G", 5); hashLetras.put("H", 6); hashLetras.put("I", 4); hashLetras.put("J", 5);

    hashLetras.put("K", 6); hashLetras.put("L", 7); hashLetras.put("M", 8); hashLetras.put("N", 9); hashLetras.put("O", 5);

    hashLetras.put("P", 6); hashLetras.put("Q", 7); hashLetras.put("R", 8); hashLetras.put("S", 9); hashLetras.put("T", 10); 

    hashLetras.put("U", 6); hashLetras.put("V", 7); hashLetras.put("W", 8); hashLetras.put("X", 9); hashLetras.put("Y", 10);

    hashLetras.put("Z", 11); hashLetras.put(" ", 7); //ESPACO

    String teste="TECNOLOGIA";

    int count=0;

    for(int i=0; i<teste.length();i++){

        if( i<(teste.length()-1) && teste.charAt(i)=='Q' && teste.charAt(i+1)=='U'){
             count = count+7;
             i++;
        }else{
            String c = teste.charAt(i)+ "";
            System.out.println("LETRA:"+ c);
            count = count+hashLetras.get(c);
            System.out.println("NUMERO DA LETRA:"+ hashLetras.get(c));
        }
    }

    System.out.println("O tempo foi de: "+count);
}
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.