Tuesday, 23 January 2018

Write a simple java application that declares Employee class. The program should generate and handle custom exceptions such as a. InvalidEmailAddressException if the address does not contains . and @ b. InvalidTelephoneNumberException if total no of digits > 10.




Program:-
class InvalidIdException extends Exception
{         
            InvalidIdException()
            {
            }
}
class NumberIsNotValidException extends Exception
{
            NumberIsNotValidException()
            {
            }
}
class employee
{
            public static void main(String args[])
            {
                        String id = args[0];
                        String num = args[1];
                        try
                        {
                                    if(id.contains("@") && id.contains("."))       
                                    {
                                                System.out.println("Email Id is correct: "+args[0]);
                                    }
                                    else
                                    {
                                                throw new InvalidIdException();
                                    }
                                   
                                    if(num.length()==10)
                                    {
                                                System.out.println("Mobile Number is correct: "+num);
                                    }
                                    else
                                    {
                                                throw new NumberIsNotValidException();
                                    }
                        }catch(InvalidIdException e)
                        {
                                                System.out.println("Id has wrong format");
                        }
                        catch(NumberIsNotValidException e)
                        {
                                                System.out.println("Please enter correct Number..");
                        }
                                               
            }
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...