Jump to content

Java Validation - Int, String, Char Needed


Recommended Posts

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)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...