Académique Documents
Professionnel Documents
Culture Documents
Question 1:
1.Define Employee class with Employee code, name, date of birth and date of appointment. The
Employee code must have the format of year-designation-number. The year is a two digit integer
such as 87. the designation is a single letter code M for manager, A for Administrative staff, H for HR
dept staff, E for Executive staff, and T for Technical staff. The number is a three digit number. The
following are some sample employee codes.
82-M-183
76-A-242
71-H-107
write a Java program to read the employee code, name, date of birth, and date of appointment and
validate the employee code. If the emplopyee code is incorrect a suitable user defined exception
must be thrown. Then verify verify if date of birth is before date of appointment. If it is not so, then
throw another user defined Exception. If it is correct, then create the Employee object, display the
count of employee and display the details of employees.
Code:
importjava.util.*;
import java.io.*;
Empl()
super();
System.out.println("Invalid date of appointment");
invalidcode()
super();
class ex
intdd,mm,yy,d,m,y;
String code,name;
ex()
name=s.next();
code=s.next();
dd=s.nextInt();
mm=s.nextInt();
yy=s.nextInt();
d=s.nextInt();
y=s.nextInt();
int tmp1,tmp2,tmp3;
tmp1=dd-d;
tmp2=mm-m;
tmp3=yy-y;
try
if(tmp3<=0)
catch(Exception e)
{System.out.println(e);}
if(code.length()==0)
else
if(Character.isDigit(code.charAt(0)) &&Character.isDigit(code.charAt(1))
&&Character.isDigit(code.charAt(5)) &&Character.isDigit(code.charAt(6))
&&Character.isDigit(code.charAt(7)))
if(Character.isLetter(code.charAt(3)))
ex e=new ex();
e.check();
e.code();
}}
Output:
Question 2:
The refractive index or index of refraction of a material is a dimensionless number that describes
how light propagates through that medium. It is defined as
n=c /v,
where c is the speed of light in vacuum and v is the phase velocity of light in the medium. For
example, the refractive index of water is 1.333, meaning that light travels 1.333 times faster in
vacuum than in the water.
In an experiment the c and v values were recorded in 10 cases and stored c[] and v[] in the form of
integers. Write a Java program to evaluate refractive index for each of the above ten cases. If any v
value happens to be zero catch approriate user-defined exception and continue with the remaining
cases.
Code:
importjava.util.Scanner;
import java.io.*;
refract()
super();
for(inti=0;i<4;i++){
c[i]=s.nextInt();
v[i]=s.nextInt();
try{
for(inti=0;i<4;i++)
if(v[i]==0)
catch(Exception e)
{System.out.println(e);}
}}
Output: