-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeacher.java
133 lines (108 loc) · 2.98 KB
/
Teacher.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Create a class ‘Employee’ with data members Empid, Name, Salary, Address and constructors to initialize the data members. Create another class ‘Teacher’ that inherit the properties of class employee and contain its own data members department, Subjects taught and constructors to initialize these data members and also include display function to display all the data members. Use array of objects to display details of N teachers.
*/
import java.util.Scanner;
class Employee {
int Empid;
String Name;
double Salary;
String Address;
Employee(int no, String na, double sal, String add) {
this.Empid = no;
this.Name = na;
this.Salary = sal;
this.Address = add;
}
}
public class Teacher extends Employee{
String dept;
String subject;
Teacher(int no, String na, double sal, String add, String dep, String sub){
super(no,na,sal,add);
this.dept= dep;
this.subject=sub;
}
void display(){
System.out.println("Employee id: "+Empid);
System.out.println("Name: "+Name);
System.out.println("Salary: "+Salary);
System.out.println("Address: "+Address);
System.out.println("Department: "+dept);
System.out.println("Subject: "+subject);
}
public static void main(String[] args) {
System.out.println("\nEnter the No. of Employee's");
Scanner sc1 = new Scanner(System.in);
int num = sc1.nextInt();
Teacher arr[]=new Teacher[num];
for(int i =0;i<num;i++)
{
Scanner sc =new Scanner(System.in);
System.out.println("\nEnter Employee id: ");
int Empid=sc.nextInt();
System.out.println("\nEnter Employee Name: ");
String Name=sc.next();
System.out.println("\nEnter Salary: ");
double Salary=sc.nextDouble();
System.out.println("\nEnter Address: ");
String Address=sc.next();
System.out.println("\nEnter department: ");
String dept=sc.next();
System.out.println("\nEnter Subject: ");
String subject=sc.next();
arr[i]=new Teacher(Empid,Name,Salary,Address,dept,subject);
}
System.out.println("\n********Informations of all the employee's************");
for(int i=0;i<num;i++){
int j=i+1;
System.out.println("\n"+j+").");
arr[i].display();
}
sc1.close();
}
}
/*
mlm@mlm-desktop:~/Desktop/Rojin/java$ javac Teacher.java
mlm@mlm-desktop:~/Desktop/Rojin/java$ java Teacher
Enter the No. of Employee's
2
Enter Employee id:
101
Enter Employee Name:
zaina
Enter Salary:
35000
Enter Address:
kottayam
Enter department:
mca
Enter Subject:
java
Enter Employee id:
102
Enter Employee Name:
alvin
Enter Salary:
36000
Enter Address:
changanasherry
Enter department:
mca
Enter Subject:
dbms
********Informations of all the employee's************
1).
Employee id: 101
Name: zaina
Salary: 35000.0
Address: kottayam
Department: mca
Subject: java
2).
Employee id: 102
Name: alvin
Salary: 36000.0
Address: changanasherry
Department: mca
Subject: dbms
*/