-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChecking_Employees.java
More file actions
63 lines (61 loc) · 1.15 KB
/
Checking_Employees.java
File metadata and controls
63 lines (61 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
class NameError extends Exception{
String s;
NameError(String s){
this.s=s;
}
// String toString(){ return s; }
}
class AgeError extends Exception{
String s;
AgeError(String s){
this.s=s;
}
// String toString(){ return s; }
}
class Employee{
String name;
int age;
Employee(String name,int age){
this.name=name;
this.age=age;
System.out.println("employee record created successfully");
}
}
class Checking_Employees{
public static void main(String args[]){
String name;
boolean flag=true;
Scanner s=new Scanner(System.in);
System.out.println("enter employee name");
name=s.next();
int h;
try{
h=Integer.parseInt(name);
flag=false;
throw new NameError("invalid name");
}
catch(NameError e){
System.out.println(e.s);
}
catch(Exception e){}
int age;
System.out.println("enter age");
age=s.nextInt();
try{
if(age>50){
flag=false;
throw new AgeError("inavlid age");
}
}
catch(AgeError e){
System.out.println(e.s);
}
if(flag==true){
Employee e=new Employee(name,age);
}
else{
System.out.println("cannot create new record due to above reasons");
}
}
}