-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathEducationSystem.java
More file actions
99 lines (88 loc) · 2.72 KB
/
Copy pathEducationSystem.java
File metadata and controls
99 lines (88 loc) · 2.72 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
import java.util.ArrayList;
interface EducationalInstitution {
String displayInfo();
}
abstract class University implements EducationalInstitution {
public String name;
public int studentCount;
public double tuitionFee;
public ArrayList<Student> students;
public boolean transferStudent(Student student, University university) {
if(this.students.contains(student)) {
return false;
}else {
this.students.remove(student);
university.students.add(student);
student.university = university;
university.studentCount++;
this.studentCount--;
return true;
}
}
University(String name, double tuitionFee) {
this.name = name;
this.tuitionFee = tuitionFee;
this.students = new ArrayList<>();
this.studentCount = 0;
}
University(String name, double tuitionFee, Student student) {
this.name = name;
this.tuitionFee = tuitionFee;
this.students = new ArrayList<>();
this.students.add(student);
this.studentCount++;
}
}
class Student implements EducationalInstitution {
private String name;
public University university;
private double balance;
public Student(String name, double balance, University university) {
setName(name);
setBalance(balance);
if(university.tuitionFee <= getBalance()) {
this.university = university;
university.students.add(this);
university.studentCount++;
}else {
System.out.println("Not Enough Balance");
}
}
@Override
public String displayInfo() {
return "Name: " + getName() + "\nUniversity: " + getUniversity().name + "\nBalance: " + getBalance();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public University getUniversity() {
return university;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getBalance() {
return balance;
}
}
class SbuUniversity extends University {
public SbuUniversity(String name, double tuitionFee) {
super(name, tuitionFee);
}
@Override
public String displayInfo() {
return "SBU University\n" + "Tuition Fee: " + this.tuitionFee + "\nStudent Count: " + this.studentCount;
}
}
class SutUniversity extends University {
SutUniversity(String name, double tuitionFee) {
super(name, tuitionFee);
}
@Override
public String displayInfo() {
return "SUT University\n" + "Tuition Fee: " + this.tuitionFee + "\nStudent Count: " + this.studentCount;
}
}