-
Notifications
You must be signed in to change notification settings - Fork 92
/
eduInstitute.java
66 lines (62 loc) · 1.6 KB
/
eduInstitute.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
package realWorldScenario;
import java.util.Scanner;
class Person {
Scanner sc = new Scanner(System.in);
public String name;
public int id;
}
class Student extends Person {
public int year;
public String course;
void getDetails() {
System.out.println("Enter name: ");
name = sc.nextLine();
System.out.println("Enter id: ");
id = sc.nextInt();
System.out.println("Enter year: ");
year = sc.nextInt();
System.out.println("Enter course: ");
course = sc.next();
System.out.println();
}
void display() {
System.out.println("Displaying student details: ");
System.out.println("Name: " + name);
System.out.println("ID: " + id);
System.out.println("Year: " + year);
System.out.println("Course: " + course);
}
}
class Teacher extends Person {
public int expYears;
public String subject;
void getDetails() {
System.out.println("Enter name: ");
name = sc.nextLine();
System.out.println("Enter id: ");
id = sc.nextInt();
System.out.println("Enter years of experience: ");
expYears = sc.nextInt();
System.out.println("Enter subject: ");
subject = sc.next();
}
void display() {
System.out.println("Displaying teacher details: ");
System.out.println("Name: " + name);
System.out.println("ID: " + id);
System.out.println("Years of experience: " + expYears);
System.out.println("Subject taught: " + subject);
}
}
public class EduInstitute {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student s1 = new Student();
s1.getDetails();
s1.display();
System.out.println();
Teacher t1 = new Teacher();
t1.getDetails();
t1.display();
}
}