-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4.java
78 lines (66 loc) · 2.1 KB
/
p4.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
import java.util.*;
class Person {
String name;
int age;
String gender;
void readDetails() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter name: ");
name = sc.nextLine();
System.out.println("Enter age: ");
age = sc.nextInt();
System.out.println("Enter gender: ");
gender = sc.next();
}
void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Gender: " + gender);
}
}
class Employee extends Person {
String company;
void readDetails() {
super.readDetails();
Scanner sc = new Scanner(System.in);
System.out.println("Enter company: ");
company = sc.nextLine();
}
void displayDetails() {
super.displayDetails();
System.out.println("Company: " + company);
}
}
class Student extends Person {
String school;
void readDetails() {
super.readDetails();
Scanner sc = new Scanner(System.in);
System.out.println("Enter school: ");
school = sc.nextLine();
}
void displayDetails() {
super.displayDetails();
System.out.println("School: " + school);
}
}
public class p4 {
public static void main(String[] args) {
Employee[] employees = new Employee[5];
Student[] students = new Student[5];
for (int i = 0; i < 5; i++) {
employees[i] = new Employee();
students[i] = new Student();
System.out.println("Enter details for employee " + (i+1) + ":");
employees[i].readDetails();
System.out.println("Enter details for student " + (i+1) + ":");
students[i].readDetails();
}
for (int i = 0; i < 5; i++) {
System.out.println("Details of employee " + (i+1) + ":");
employees[i].displayDetails();
System.out.println("Details of student " + (i+1) + ":");
students[i].displayDetails();
}
}
}