loop, int input and try/catch Exception probelm
Dear guys,
need some help.
below is part of my program,
first problem i need to loop if users input is not numeric(integer or double)
i know that i need a do while loop, but got problem in declaring the while statement.
also please see the questions indicated below at \\.....
for(......)
{
String quantityStr = JOptionPane.showInputDialog (null,"Enter part " +(index+1) +" quantity:");
try
{
Integer.parseInt(quantityStr);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Not an integer, please enter numeric values");
}
String priceStr = JOptionPane.showInputDialog (null,"Enter part " +(index+1) +" price per unit:");
try
{
Double.parseDouble(priceStr);
}
catch (NumberFormatException e)
{
JOptionPane.showMessageDialog(null,"Not an integer, please enter numeric values");
}
quantity = Integer.parseInt(quantityStr);
price = Double.parseDouble(priceStr);
\\"sorry, if this question sounds stupid just learn java, why i have to"
\\"declare the 2 statement above again when it already been declare already, of course if i don't do it ,"
\\"it will show error on could not find quantity and price, i know that this is due to out of scope but is"
\\"there anyway i can put the 3 statement below within the scope?"
\\"if yes, where?"
inv[index] =new Invoice(quantity,price);
inv[index].setpartQuantity(quantity);
inv[index].setpriceUnit(price);
}

