forked from manibhushan20/OOPs-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentClassses.java
More file actions
90 lines (75 loc) · 2.52 KB
/
StudentClassses.java
File metadata and controls
90 lines (75 loc) · 2.52 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
class Student {
private int studentID;
private String name;
private double annualTuitionFee;
// Constructor requiring ID number and name
public Student(int studentID, String name) {
this.studentID = studentID;
this.name = name;
}
// Getters and setters for fields
public int getStudentID() {
return studentID;
}
public void setStudentID(int studentID) {
this.studentID = studentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getAnnualTuitionFee() {
return annualTuitionFee;
}
public void setAnnualTuitionFee(double annualTuitionFee) {
this.annualTuitionFee = annualTuitionFee;
}
}
class UndergraduateStudent extends Student {
public UndergraduateStudent(int studentID, String name) {
super(studentID, name);
setTuition(40000);
}
public void setTuition(double semesterFee) {
setAnnualTuitionFee(semesterFee * 2); // Two semesters in a year
}
}
class GraduateStudent extends Student {
public GraduateStudent(int studentID, String name) {
super(studentID, name);
setTuition(30000);
}
public void setTuition(double semesterFee) {
setAnnualTuitionFee(semesterFee * 2); // Two semesters in a year
}
}
class ResearchScholar extends Student {
public ResearchScholar(int studentID, String name) {
super(studentID, name);
setTuition(15000);
}
public void setTuition(double semesterFee) {
setAnnualTuitionFee(semesterFee * 2); // Two semesters in a year
}
}
public class StudentClassses {
public static void main(String[] args) {
// Creating an array of at least six objects for demonstration
Student[] students = new Student[6];
students[0] = new UndergraduateStudent(1, "John");
students[1] = new UndergraduateStudent(2, "Alice");
students[2] = new GraduateStudent(3, "Bob");
students[3] = new GraduateStudent(4, "Eve");
students[4] = new ResearchScholar(5, "Mike");
students[5] = new ResearchScholar(6, "Sara");
// Displaying student information
for (int i=0;i<6;i++) {
System.out.println("Student ID: " + students[i].getStudentID());
System.out.println("Name: " + students[i].getName());
System.out.println("Annual Tuition Fee: " + students[i].getAnnualTuitionFee());
System.out.println();
}
}
}