-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEducationSystem.java
More file actions
155 lines (143 loc) · 5.26 KB
/
Copy pathEducationSystem.java
File metadata and controls
155 lines (143 loc) · 5.26 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.util.ArrayList;
//
//public class Main {
// public static void main(String[] args) {
// // ایجاد دو دانشگاه
// University sbu = new SbuUniversity("SBU", 5000);
// University sut = new SutUniversity("SUT", 4000);
//
// // ایجاد دانشجوها
// Student student1 = new Student("Ali", 6000, sbu);
// Student student2 = new Student("Sara", 3000, sut);
// Student student3 = new Student("Reza", 5000, sut);
// Student student4 = new Student("Mina", 4500, sbu);
// Student student5 = new Student("Nima", 7000, sbu);
// Student student6 = new Student("Laleh", 3500, sut);
// Student student7 = new Student("Hassan", 4800, sbu);
// Student student8 = new Student("Elham", 5200, sut);
//
// // نمایش اطلاعات دانشجویان
// System.out.println(student1.displayInfo());
// System.out.println("------------------");
// System.out.println(student3.displayInfo());
// System.out.println("------------------");
// System.out.println(student5.displayInfo());
// System.out.println("------------------");
// System.out.println(student8.displayInfo());
// System.out.println("------------------");
//
// // نمایش اطلاعات دانشگاهها
// System.out.println(sbu.displayInfo());
// System.out.println("------------------");
// System.out.println(sut.displayInfo());
// System.out.println("------------------");
//
// // انتقال دانشجو از SBU به SUT
// System.out.println("Transferring Ali from SBU to SUT...");
// boolean transferResult = sbu.transferStudent(student1, sut);
// System.out.println("Transfer Successful: " + transferResult);
//
// // نمایش اطلاعات دانشگاهها بعد از انتقال
// System.out.println(sbu.displayInfo());
// System.out.println("------------------");
// System.out.println(sut.displayInfo());
// System.out.println("------------------");
//
// // نمایش اطلاعات دانشجویان بعد از انتقال
// System.out.println(student1.displayInfo());
// System.out.println("------------------");
// System.out.println(student3.displayInfo());
// System.out.println("------------------");
// System.out.println(student5.displayInfo());
// System.out.println("------------------");
// System.out.println(student8.displayInfo());
// System.out.println("------------------");
// }
//}
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;
}
}