Excersise: 8 Own Exception For Employee | Java | Tamizhan Goals

Own Exception For Employee

Excersise: 8

    Create Our Own Exception for Employees.
        (Constraints 1.Age > 18 and < 58 2.Dept No. 10 || 20 || 30 || 40 )

Program


      
import java.io.*;
class myex extends Exception
{
private int age;
myex(int age1)
  	 {
age=age1;
   }
}
class myex1 extends Exception
{
private int dno;
myex1(int dno1)
   	   {
dno=dno1;
  	    }
}
class emp
{
static void comp(int age)throws myex
     	 {
System.out.println("Your age is:"+age);
if(age>18&&age<=58)
throw new myex(age);
System.out.println("Your not eligble for this job");
 	     }
static void comp1(int d)
{
try 
     			  {
System.out.println("Your department no is"+d);
if((d==10)||(d==20)||(d==30)||(d==40))
  				         {                         
throw new myex1(d); 
      				          }
else
System.out.println("Your designation is unknown");
  			     }
catch(myex1 e)
{
 if((d==10)||(d==20)||(d==30)||(d==40))
System.out.println("You are a member of our department");
}
}
 public static void main(String arg[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int a,d1;
System.out.println("Enter the Employee age:");
a=Integer.parseInt(br.readLine());
try
      		 {
comp(a);
  }
catch(myex e)
    		   {
System.out.println("You are eligible for this job");
    }
finally
    		   {
if(a>18&&a<58)
System.out.println("Enter the department no:");
d1=Integer.parseInt(br.readLine());
comp1(d1);
       }
  	  }
  }

Output

Post a Comment

Thanks for your comments. Please be visit and given positive review on our site.

Previous Post Next Post