DAA Program 2 Staff

Design  a  superclass  called Staff  with  details  as  StaffId,  Name,  Phone,  Salary. Extend   this   class   by   writing   three   subclasses   namely Teaching   (domain, publications), Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff objects of all three categories.

1  package program2.staff;
2 
3  public class Staff {
4 
5          protected String staffId;
6          protected String name;
7          protected String phone;
8          protected String salary;
9 
10         public Staff(String staffId, String name, String phone, String salary) {
11 
12                 this.staffId = staffId;
13                 this.name = name;
14                 this.phone = phone;
15                 this.salary = salary;
16         }
17 
18         @Override
19         public String toString() {
20 
21                 return "Staff [staffId=" + staffId + ", name=" + name + ", phone=" + phone + ", salary=" + salary + "]";
22 
23         }
24 
25 }
26 
27 package program2.staff;
28 
29 import java.util.Arrays;
30 
31 public class Teaching extends Staff {
32 
33         private String domain;
34         private String[] publications;
35 
36         public Teaching(String staffId, String name, String phone, String salary, String domain, String[] publications) {
37 
38                 super(staffId, name, phone, salary);
39 
40                 this.domain = domain;
41                 this.publications = publications;
42 
43         }
44 
45         @Override
46         public String toString() {
47                 return "Teaching " + super.toString() + "\n" + "[domain=" + domain + ", publications="
48                                 + Arrays.toString(publications) + "]";
49         }
50 
51 }
52 
53 package program2.staff;
54 
55 import java.util.Arrays;
56 
57 public class Technical extends Staff {
58 
59         private String[] skills;
60 
61         public Technical(String staffId, String name, String phone, String salary, String[] skills) {
62 
63                 super(staffId, name, phone, salary);
64 
65                 this.skills = skills;
66 
67         }
68 
69         @Override
70         public String toString() {
71                 return "Technical " + super.toString() + "\n" + "[skills=" + Arrays.toString(skills) + "]";
72         }
73 
74 }
75 
76 package program2.staff;
77 
78 public class Contract extends Staff {
79 
80         private String period;
81 
82         public Contract(String staffId, String name, String phone, String salary, String period) {
83 
84                 super(staffId, name, phone, salary);
85 
86                 this.period = period;
87 
88         }
89 
90         @Override
91         public String toString() {
92                 return "Contract " + super.toString() + "\n" + "[period=" + period + "]";
93         }
94 
95 }
96 
97 package program2.staff;
98 
99 import java.util.Scanner;
100
101public class StaffDemo {
102
103        public static void menu() {
104
105                System.out.println("\n\tMENU");
106
107                System.out.println("1. Teaching Staff Entry");
108                System.out.println("2. Technical Staff Entry");
109                System.out.println("3. Contract Staff Entry");
110
111                System.out.println("4. Display Staff Details");
112
113                System.out.println("5. Exit");
114
115        }
116
117        public static String[] readStaffData() {
118
119                Scanner s = new Scanner(System.in);
120                String[] data = new String[4];
121
122                System.out.println("Staff Id: ");
123                data[0] = s.next();
124                System.out.println("Name: ");
125                data[1] = s.next();
126                System.out.println("Phone: ");
127                data[2] = s.next();
128                System.out.println("Salary: ");
129                data[3] = s.next();
130
131                return data;
132
133        }
134
135        public static void main(String[] args) {
136
137                String[] data;
138                int staffCount = 0;
139                int n;
140
141                Staff[] staff = new Staff[15];
142
143                Scanner s = new Scanner(System.in);
144
145                for (;;) {
146
147                        menu();
148
149                        System.out.println("\nEnter your choice: ");
150                        int ch = s.nextInt();
151
152                        switch (ch) {
153
154                        case 1:
155                                System.out.println("\nEnter Teaching Staff details one / one");
156
157                                data = readStaffData();
158
159                                System.out.println("Domain: ");
160                                String domain = s.next();
161
162                                System.out.println("Publications count: ");
163                                n = s.nextInt();
164
165                                String[] publications = new String[n];
166                                System.out.println("Give " + n + " Publication details one / one");
167                                for (int i = 0; i < n; ++i) {
168                                        publications[i] = s.next();
169                                }
170
171                                staff[staffCount++] = new Teaching(data[0], data[1], data[2], data[3], domain, publications);
172
173                                break;
174
175                        case 2:
176                                System.out.println("Enter Technical Staff details one / one");
177
178                                data = readStaffData();
179
180                                System.out.println("Skills count: ");
181                                n = s.nextInt();
182
183                                String[] skills = new String[n];
184                                System.out.println("Give " + n + " Skill details one / one");
185                                for (int i = 0; i < n; ++i) {
186                                        skills[i] = s.next();
187                                }
188
189                                staff[staffCount++] = new Technical(data[0], data[1], data[2], data[3], skills);
190
191                                break;
192
193                        case 3:
194                                System.out.println("Enter Contract Staff details one / one");
195
196                                data = readStaffData();
197
198                                System.out.println("Period: ");
199                                String period = s.next();
200
201                                staff[staffCount++] = new Contract(data[0], data[1], data[2], data[3], period);
202
203                                break;
204
205                        case 4:
206                                System.out.println("Staff details are...\n");
207                                for (int i = 0; i < staffCount; ++i) {
208                                        System.out.println(staff[i]);
209                                        System.out.println();
210                                }
211                                break;
212
213                        case 5:
214                                System.exit(0);
215
216                        }
217
218                }
219
220        }
221
222}


OUTPUT:

MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 1

Enter Teaching Staff details one / one

Staff Id: CS111

Name: John

Phone: 987654321

Salary: 30000

Domain: CSE

Publications count: 3

Give 3 Publication details one / one

IJSTR

STS

OAJST

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 1

Enter Teaching Staff details one / one

Staff Id: ISE

Name: Jack

Phone: 978456321

Salary: 30000

Domain: ISE

Publications count: 4

Give 4 Publication details one / one

IJSTR

STS

OAJST

JMST

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 1

Enter Teaching Staff details one / one

Staff Id: CS333

Name: Tony

Phone: 978456321

Salary: 35000

Domain: CSE

Publications count: 2

Give 2 Publication details one / one

JMST

OAJST

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 2

Enter Technical Staff details one / one

Staff Id: TS111

Name: Depp

Phone: 978736521

Salary: 25000

Skills count: 3

Give 3 Skill details one / one

C

C++

JAVA

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 2

Enter Technical Staff details one / one

Staff Id: TS121

Name: Angelina

Phone: 789456123

Salary: 25000

Skills count: 4

Give 4 Skill details one / one

C

PYTHON

R

HTML

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 2

Enter Technical Staff details one / one

Staff Id: TS123

Name: Cruise

Phone: 789123456

Salary: 20000

Skills count: 2

Give 2 Skill details one / one

HTML

JavaScript

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 3

Enter Contract Staff details one / one

Staff Id: CF100

Name: John Travolta

Phone: 987451236

Salary: 15000

Period: 1

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 3

Enter Contract Staff details one / one

Staff Id: CF120

Name: Arnold

Phone: 456789123

Salary: 15000

Period: 2

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 3

Enter Contract Staff details one / one

Staff Id: CF130

Name: Kate

Phone: 123456789

Salary: 10000

Period: 3

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice: 4

Staff details are...

Teaching Staff [staffId=CS111, name=John, phone=987654321, salary=30000]

[domain=CSE, publications=[IJSTR, STS, OAJST]]

Teaching Staff [staffId=ISE111, name=Jack, phone=978456321, salary=30000]

[domain=ISE, publications=[IJSTR, STS, OAJST, JMST]]

Teaching Staff [staffId=CS333, name=Tony, phone=978456321, salary=35000]

[domain=CSE, publications=[JMST, OAJST]]

Technical Staff [staffId=TS111, name=Depp, phone=978736521, salary=25000]

[skills=[C, C++, JAVA]]

Technical Staff [staffId=TS121, name=Angelina, phone=789456123, salary=25000]

[skills=[C, PYTHON, R, HTML]]

Technical Staff [staffId=TS123, name=Cruise, phone=789123456, salary=20000]

[skills=[HTML, JavaScript]]

Contract Staff [staffId=CF100, name=John, phone=Travolta, salary=15000]

[period=1]

Contract Staff [staffId=CF120, name=Arnold, phone=456789123, salary=15000]

[period=2]

Contract Staff [staffId=CF130, name=Kate, phone=123456789, salary=10000]

[period=3]

        MENU

1. Teaching Staff Entry

2. Technical Staff Entry

3. Contract Staff Entry

4. Display Staff Details

5. Exit

Enter your choice:

5


No comments:

Post a Comment

Online Certifications

Python for Beginners Offered by: Christian Drumm, Stephan Jacobs Course dates: 2022-04-05 to 2022-06-01 Topics Python Fundamentals Lists and...