modmouse Posted January 10, 2012 Posted January 10, 2012 I'm after validation for these bellow with an explanation to what I'm trying to attempt for each one. public void setPrice(int aPrice)throws DishException { if (aPrice < 0) throw new DishException ("Price cannot not be a negative number"); price = aPrice; } Only accept numbers, and cannot be empty. public void setType(char aType) throws DishException { if(aType == 0) throw new DishException ("A dish type must be entered"); type = aType; } Only accept one letter from the following [s,m,d or S,M,D] public void setName (String aName)throws DishException { if(aName.length() == 0) throw new DishException ("A dish name must be entered"); name = aName; } Only allow words no numbers or symbols Any help would be great B) Quote
Mr-Protocol Posted January 10, 2012 Posted January 10, 2012 Cool homework, bro. Yeah, reading the book helps. I haven't done any C in a while to even attempt to help out. Python has spoiled me :) Whoops, thought it was C. It's Java, I've never coded java so I'm equally screwed lol. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.