BigDecimal - Help formulating if statments
Hi, i'm new here, just joined and this is my first post. I'm working on a project for my first java class and i've run into a bit of a snag.
I'm trying to make an if statement using the BigDecimal class.
The issue is that i can only accept inputs of 1, 2, 8 etc.
How do i form an if statement so I can Display an error message only when an invalid entry is made?
Code:
nbrPrintsInput = JOptionPane.showInputDialog("You can order 1, 2, 8, 10, 25, 30, or 50 Prints\n" +
"Please Enter a Valid Number of Prints");
try{
nbrPrints = new BigDecimal (nbrPrintsInput);
}catch (NumberFormatException nfExRollsIn){
JOptionPane.showMessageDialog(null, "Error: You Have Entered an Invalid Quantity\n" +
"Exiting Program\n" + "Please Start Over");
System.exit(0);
}catch (Exception exRollsIn){
JOptionPane.showMessageDialog(null, "Error: You Have Entered an Invalid Quantity\n" +
"Exiting Program\n" + "Please Start Over");
System.exit(0);
}finally{
if (nbrPrintsInput == null){
JOptionPane.showMessageDialog(null, "Now Exiting Program");
System.exit(0);
}else if(nbrPrints != new BigDecimal("1")){
JOptionPane.showMessageDialog(null, "Error: You Have Entered an Invalid Quantity\n" +
"Exiting Program\n" + "Please Start Over");
System.exit(0);
}
}
at the end of the try statment there is a finally block, the first els if statement is where is have ended, not knowing how to progress.
On a side note i find it strange that our professor told us to have the program close when invalid entries occur, when it's just as easy to make a loop and have the user reenter the information
(^_^)V ~ Thanks for your time guys, nice to meet ya!