Doubt on how to use Hashmap [closed]

-2

I'm having a question about using Hashmap of Java. On that occasion, I have a class with the Hashmap custo attribute.

In this class, I need to create a constructor and in this constructor, I need to request the insertion of 3 integers that will make up my cost (gold, wood and diamond).

My question is: how do I request these 3 data in order to fill them at my cost? And how do I display and use them later?

    
asked by anonymous 14.11.2018 / 17:22

1 answer

-1

I believe that's what you want.

Hugs

    //CRIANDO O MAP CUSTO
    HashMap<String, Integer> custo = new HashMap<String, Integer>();

    //PEDINDO A INFORMAÇÃO PARA O USUÁRIO
    System.out.println("DIGITE A QUANTIDADE DE OURO");
    Scanner readOuro = new Scanner(System.in);

    //OBTENDO A INFORMAÇÃO DO TECLADO
    Integer qtdOuro = readOuro.nextInt();

    //INSERINDO A QUANTIDADE DE OURO AO MAPA COM A CHAVE OURO
    custo.put("OURO", qtdOuro);


    //FAZENDO A MESMA COISA PARA MADEIRA E DIAMANTE

    System.out.println("DIGITE A QUANTIDADE DE MADEIRA");
    Scanner readMadeira = new Scanner(System.in);
    Integer qtdMadeira = readMadeira.nextInt();
    custo.put("MADEIRA", qtdMadeira);




    System.out.println("DIGITE A QUANTIDADE DE DIAMANTE");
    Scanner readDiamante = new Scanner(System.in);
    Integer qtdDiamante = readDiamante.nextInt();
    custo.put("DIAMANTE", qtdDiamante);
    
14.11.2018 / 17:36