-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab15.java
More file actions
64 lines (61 loc) · 2.05 KB
/
Copy pathjavalab15.java
File metadata and controls
64 lines (61 loc) · 2.05 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
64
import java.util.*;
class myException extends Exception{
public myException (String m){
super (m);
}
}
class Employee{
public String name;
public int e_id,dept_id;
}
public class javalab15 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of employees:");
int n = sc.nextInt();
sc.nextLine();
String name;
int e_id,dept_id;
Employee []ob = new Employee[n];
try{
for(int i=0; i<n; i++){
ob[i] = new Employee();
System.out.println("Details for Employee" + (i+1));
System.out.print("Enter name:");
name = sc.nextLine();
if(!Character.isUpperCase(name.charAt(0))){
throw new myException("first letter should be capital");
}
else{
ob[i].name=name;
}
System.out.print("Enter employee Id:");
e_id = sc.nextInt();
if(e_id>=2002 && e_id<=5001){
ob[i].e_id=e_id;
}
else{
throw new myException("Employee Id should be between 2001 and 5001");
}
System.out.print("Enter Department Id:");
dept_id = sc.nextInt();
if(dept_id>=1 && dept_id<=5){
ob[i].dept_id=dept_id;
}
else{
throw new myException("department Id should be between 1 and 5");
}
sc.nextLine();
}
sc.close();
System.out.println("\nEntered Employee Details:");
for (int i = 0; i < n; i++) {
System.out.println("Employee " + (i + 1) + ": " +
"Name: " + ob[i].name + ", ID: " + ob[i].e_id + ", Dept ID: " + ob[i].dept_id);
}
}
catch(myException obj){
System.out.println(obj.toString());
}
}
}