Handling bad input with a Class
<p>Here's a constructor I have for Electronics that checks if the State input is valid. </p>

<pre><code>public Electronics(String name, double price, int quantity, double weight, boolean frag, String s)
    {
        super("Electronics",name,price,quantity,weight);
        fragile=frag;
        s=s.toUpperCase();
        if(checkState(s)==true)
        {
            state=s;
        }
        else
        {
            out.println("ERROR - not a valid state abbreviation");
        }
    }
</code></pre>

<p>However in my <code>main()</code>, I have something like this:</p>

<pre><code>public List&lt;Item&gt; shoppingCart = new ArrayList&lt;Item&gt;();
temp= new Electronics(name,price,quantity,weight, fragile, state);
...
shoppingCart.add(temp);
</code></pre>

<p>So even if the state abbreviation is not valid, (it just prints out that state is not valid) but the object is still added to the ArrayList. What can I do to stop the add if the state abbreviation is not correct?</p>
