Documente Academic
Documente Profesional
Documente Cultură
Employee {
int age;
int empId;
String empName;
er.addEmployee();
System.out.println("END");
/*try
{
if(e.getAge()<18)
{
System.out.println(e.getAge());
throw new AgeMisMatchException("age less than
18");
}
}
catch(AgeMisMatchException exp)
{
System.out.println(exp.getMessage());
}System.out.println("END");
}*/
public void addEmployee() throws AgeMisMatchException
{
Employee e=new Employee();
package excepeg2;
import java.util.Scanner;
public class Division {
public static void main(String[] args)
{
Division d=new Division();
// TODO Auto-generated method stub
try
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter a:");
int a=sc.nextInt();
System.out.println("Enter b:");
int b=sc.nextInt();
double res=d.division(a,b);
if(res!=0)
throw new ArithmeticException("Not divisible");
}
catch(ArithmeticException exp)
{
System.out.println(exp.getMessage());
}System.out.println("END");
}
public double division(int a,int b)
{
// TODO Auto-generated constructor stub
return a%b;
}
}
-------------------------package excepeg2;
class AgeException extends Exception
{
}
package excepeg2;
public class Person
}
package excepeg2;
public class SupplyPerson
{
public static void main(String args[])
{
int age=0;
if(args.length>0)
{
try
{
age=Integer.parseInt(args[0]);
}
catch(NumberFormatException e)
{
System.out.println("Must enter integer as first
argument.");
return;
}
}
else
{
System.out.println("Must enter age as first
argument..");
return;
}
Person p=new Person();
p.setAge(age);
VirtualJob j=new VirtualJob();
VirtualCompany.fillJob(j,p);
}
}
package excepeg2;
class TooOldException extends AgeException {
}
package excepeg2;
class TooYoungException extends AgeException {
}
package excepeg2;
public class VirtualCompany
{
public static void fillJob(VirtualJob j,Person p)
{
try
{
j.applyJob(p);
System.out.println("Age is right.");
}
catch(AgeException e)
{
System.out.println("Age is tooOld or tooYoung");
}
}
package excepeg2;
public class VirtualJob
{
private static final int tooOld=35;
private static final int tooYoung=15;
public void applyJob(Person p) throws
TooOldException,TooYoungException
{
int age=p.getAge();
if(age>= tooOld)
{
throw new TooOldException();
}
else if (age<=tooYoung)
{
throw new TooYoungException();
}