Loading...
Loading...
A school prints ID cards. Every person has a name and an age; a student card also shows the class, and a teacher card shows the subject.
Write Person with private name and age and String card(). Write Student (adds grade) and Teacher (adds subject); each gives its own card() that starts with the parent's card by calling super.card().
S name age grade or T name age subject (one-word name and subject).name, age | Student, class g or name, age | Teacher, subject. Then STUDENTS s TEACHERS k.Example
Input
3 S Asha 16 11 T Ravi 41 Physics S Kiran 6 1
Output
Asha, 16 | Student, class 11 Ravi, 41 | Teacher, Physics Kiran, 6 | Student, class 1 STUDENTS 2 TEACHERS 1
Each card begins with the shared part from Person.
Try the problem first. Open one hint at a time.
super.card() runs the parent version of the method from inside the child version.
The child cannot read name (it is private), but super.card() already contains it.
Count students and teachers in main while you read the lines.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor