Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
Java index name
String nameOfTools = "";

  for( int index = 0; index < userToolType; index++ )
  {
     nameOfTools = JOptionPane.showInputDialog( "Please enter name of tool " + ( index + 1 ) );

     //check blank
     if ( nameOfTools.equalsIgnoreCase("") )
     {
        JOptionPane.showMessageDialog(null, "You entered blank");
        System.exit( 0 );
     }

  }
  //Ask the number to buy for each tool
  String numberOfTools;
  double toolsNumber = 0;
  String amountOfTools;
  double moneyForTools;
  double totalMoneyToPay = 0;
  for ( int index = 0; index < userToolType; index++ )
  {
     numberOfTools = JOptionPane.showInputDialog( "How many you need to buy " + ( index + 1 ) );
     toolsNumber = Double.parseDouble( numberOfTools );

I want the dialog to show "How many you need to by (a tool's name)" not index number how can I do this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You need then to create an ArrayList<String> to store the names of tools, something like this:

ArrayList<String> toolsNames = new ArrayList<String>(); // to take all names
for( int index = 0; index < userToolType; index++ ){
    String input = JOptionPane.showInputDialog( "Please enter name of tool " + ( index + 1 ) );
     if ( input.equals("") ){ //check blank
          JOptionPane.showMessageDialog(null, "You entered blank");
          System.exit( 0 );
     }
     toolsNames.add(input); // if it's not blank
}
//Ask the number to buy for each tool
String numberOfTools;
double toolsNumber = 0;
String amountOfTools;
double moneyForTools;
double totalMoneyToPay = 0;
for ( int index = 0; index < userToolType; index++ ){
       numberOfTools = JOptionPane.showInputDialog( "How many you need to buy from " + toolsNames.get(index));
       toolsNumber = Double.parseDouble( numberOfTools );
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda