I am working on a project and am stuck on something. The project calculates sales commissions from a company. The user inputs the persons first name,last name and then it prompts to collect the amounts of items sold in a variable called input. I am stuck on how to validate to ensure the selection is numeric only. Any help would be greatly appreciated.
Here is the code below:
public void start(){
FirstName=JOptionPane.showInputDialog("Enter sales person First Name :");
LastName=JOptionPane.showInputDialog("Enter sales person Last Name :");
input=JOptionPane.showInputDialog(null, "Enter number of items sold for product" +" "+ productCounter +" :");
while (productCounter <4){
productCounter++;
quantity=Integer.parseInt(input);
if (productCounter==1){
tot1 = quantity * Item1Price;
}else if (productCounter==2){
tot2 =quantity*Item2Price;
} else if (productCounter==3){
tot3 =quantity*Item3Price;
} else if (productCounter==4)
tot4 =quantity*Item4Price;
}//end while
Here is the code below:
public void start(){
FirstName=JOptionPane.showInputDialog("Enter sales person First Name :");
LastName=JOptionPane.showInputDialog("Enter sales person Last Name :");
input=JOptionPane.showInputDialog(null, "Enter number of items sold for product" +" "+ productCounter +" :");
while (productCounter <4){
productCounter++;
quantity=Integer.parseInt(input);
if (productCounter==1){
tot1 = quantity * Item1Price;
}else if (productCounter==2){
tot2 =quantity*Item2Price;
} else if (productCounter==3){
tot3 =quantity*Item3Price;
} else if (productCounter==4)
tot4 =quantity*Item4Price;
}//end while