-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLab5.java
More file actions
109 lines (94 loc) · 2.54 KB
/
Lab5.java
File metadata and controls
109 lines (94 loc) · 2.54 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
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
/*5. Design a super class called staff with details as staff id, name, phone number and salary.
Extend this class by writing 3 sub classes namely teaching (domain,publications), technical (skills) and contract (period).
Write a JAVA program to read and display the staff objects of all 3 categories*/
import java.util.Scanner;
class Staff {
String sid, name, phone, salary;
Scanner s = new Scanner(System.in);
void read() {
System.out.println("Enter SID,Name,Phone No.,Salary");
sid = s.nextLine();
name = s.nextLine();
phone = s.nextLine();
salary = s.nextLine();
}
void display() {
System.out.print(sid + "\t" + name + "\t" + phone + "\t" + salary + "\t");
}
}
class Teaching extends Staff {
String domain, publication;
void read() {
super.read();
System.out.println("Enter domain, publication");
domain = s.nextLine();
publication = s.nextLine();
}
void display() {
super.display();
System.out.print(domain + "\t" + publication + "\n");
}
}
class Technical extends Staff {
String skill;
void read() {
super.read();
System.out.println("Enter skill");
skill = s.nextLine();
}
void display() {
super.display();
System.out.print(skill + "\n");
}
}
class Contract extends Staff {
String period;
void read() {
super.read();
System.out.println("Enter period");
period = s.nextLine();
}
void display() {
super.display();
System.out.print(period + "\n");
}
}
public class Lab5 {
public static void main(String[] args) {
Teaching t = new Teaching();
t.read();
System.out.println("SID\tName\tPhone No.\tSalary\tDomain\tPublication");
t.display();
Technical th = new Technical();
th.read();
System.out.println("SID\tName\tPhone No.\tSalary\tSkill");
th.display();
Contract c = new Contract();
c.read();
System.out.println("SID\tName\tPhone No.\tSalary\tPeriod");
c.display();
}
}
/*
* Output:
*
* Enter SID,Name,Phone No.,Salary
* 1 A 123 1000
* Enter domain, publication
* CSE IEEE
* SID Name Phone No. Salary Domain Publication
* 1 A 123 1000 CSE IEEE
* Enter SID,Name,Phone No.,Salary
* 2 B 456 2000
* Enter skill
* Java
* SID Name Phone No. Salary Skill
* 2 B 456 2000 Java
* Enter SID,Name,Phone No.,Salary
* 3 C 789 3000
* Enter period
* 3
* SID Name Phone No. Salary Period
* 3 C 789 3000 3
*
*/