أمثلة وتمارين محلولة في لغة جافا
تمارين محلولة في لغة البرمجة جافا مأخوذة من منهاج أكاديمي
إليك تمارين وأمثلة في البرمجة الموجهة في لغة البرمجة جافا مع الحلول.
الأسئلة جميعها مترابطة مع بعضها لإتمام كتابة وظائف في نفس البرنامج.
الحلول المطروحة هي حلول ممكنة وليست حلولًا مثاليّة.
الأسئلة
السؤال الأول
يتطلب كتابة برنامج لإدارة الطلاب حيث يتم حفظ الطلاب والمواد الدراسية ويقوم الطلاب لاحقًا بتسجيل أو إلغاء تسجيل أنفسهم في المواد.
البرنامج الرئيسي يكون في الملف: Main.java (انظر الكود أدناه)
والمطلوب هو:
-
كتابة أصناف (class) للطالب والجامعة: Student.java و University.java
-
حفظ هذه الأصناف في نفس مجلد Main.java
-
كتابة الوظائف المطلوبة أدناه في مكان العبارة TODO
في النهاية يجب أن يكون البرنامج قادرًا على إنشاء طلاب وحفظهم وعرضهم.
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
University uni = new University();
// فكر هنا كيف يمكن إضافة الطلاب للجامعة
// هل يتطلب مصفوفة أم نوع بيانات أخرى؟
int operation = 0;
while (operation != 6) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
System.out.println("6- End Programm");
Scanner r = new Scanner(System.in);
operation = r.nextInt();
switch (operation) {
case 1:
/* TODO
أ) اطلب من المستخدم إدخال معلومات الطالب
ب) قم بإنشاء نموذج instance للصنف Student مع هذه المعلومات
ج) احفظ النموذج في برنامجنا نظام إدارة الطلاب
break;
case 2:
/* TODO
أ) قم بعرض رقم الطالب على الشاشة والاسم والكنية لكل الطلاب الذين تم حفظهم
*/
break;
}
}
}
}
السؤال الثاني
يتطلب تطوير البرنامج السابق بحيث:
أ. تطوير صنف الطالب Student وفق التالي:
-
إعادة كتابة دالة equals في صنف java.lang.Object (حيث ينبغي اعتبار عنصرين من صنف Student متساويين في حال كان رقم الطالب الخاص بهم متساو)
-
إعادة كتابة الدالة toString في صنف java.lang.Object ( الـ String الخاص بالعناصر من صنف Student يجب أن تكون على الشكل “رقم الطالب، الاسم الكنية” حيث تُكتب الكنية بأحرف كبيرة). حيث يتم استخدام دالة toString() عند استعراض الطلاب المخزنين في النظام.
ب. إجراء تغيير في صنف University بحيث يُحفظ الطلاب في شعاع java.util.Vector بدلًا من مصفوفة
ج. تطوير الصنف الرئيسي Main بحيث يمكن للمستخدم إضافة طلاب فقط في حالة عدم توافرهم أصلا في النظام. في حالة وجود الطالب مسبقًا وأراد المستخدم إضافته فستظهر رسالة خطأ توضح السبب.
عند كتابة البرنامج يرجى الانتباه للنقاط التالية:
-
يجب أن يحوي صنف Student على عشر متغيرات على الأقل
-
جميع المتغيرات في جميع الأصناف يجب أن تكون من نوع private وأن تحوي قيمة ابتدائية (غير الصفر أو null)
-
يجب أن يحوي الصنف Student على دالتي بناء (Constructors) على الأقل. ويجب عدم السماح بإنشاء عنصر طالب Student بدون رقم الطالب. ويمكن إنشاء عنصر طالب برقم طالب واسم وكنية.
-
يجب أن يحوي الصنف University على دالتي بناء على الأقل. يجب عدم السماح بإنشاء عنصر جامعة University بدون اسم الجامعة.
-
الانتباه لتنسيق الكود وبحيث يتم إزاحة الأسطر البرمجية في كل مجموعة { .. }
السؤال الثالث
لقد قمتَ بإعطاء المستخدم في البرنامج الرئيسي إمكانية إنشاء عناصر (object) جديدة من صنف الطالب Student وحفظها في عناصر من صنف الجامعة University class في حال عدم وجود تلك الطلاب في النظام مسبقًا.
مهامك الجديدة هي:
أ. تطوير الصنف الرئيسي Main بحيث يتم كتابة الوظائف المُعلّمة بـ TODO في الكود أدناه.
ب. إنشاء أصناف للمدرِّس Lecturer والمواد الدراسية Lessons
ج. ستلاحظ أن صنف المُدرِّس يشترك مع صنف الطالب في العديد من المتغيرات. استخدم مفهوم الوراثة وقم بإنشاء صنف شخص Person والذي يرث المتغيرات المشتركة من كلا الصنفين السابقين.
د. تطوير صنف الطالب بحيث يزوّد دالة ثابتة static للتأكد من رقم الطالب. يتم استدعاء هذه الدالة من الصنف الرئيسي Main لإظهار رسالة خطأ للمستخدم في حال أدخل رقمًا للطالب مخالفًا للقواعد التالية (أو أحدها):
-
يُسمح لرقم الطالب أن يحوي أرقامًا فقط.
-
يجب أن يكون طول رقم الطالب 7 أرقامًا.
-
لا يُسمح ﻷول رقم أن يكون صفرًا
هـ. إعادة كتابة صنف الجامعة University بحيث تستخدم خاصية generics لشعاع (Vector) الصنف بحيث يمكن حفظ العناصر من نفس الصنف فقط في عناصر الشعار Vector-Objects
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
University uni = new University();
int operation = 0;
while (operation != 16) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
System.out.println("6- add a Lecturer");
System.out.println("7- view the Lecturers ");
System.out.println("8- search Lecturer");
System.out.println("9- edit Lecturer info");
System.out.println("10- delete Lecturer");
System.out.println("11- add Lesson");
System.out.println("12- view the Lessons");
System.out.println("13- search Lesson");
System.out.println("14- edit Lesson info");
System.out.println("15- delete Lesson");
System.out.println("16- End Programm");
Scanner r = new Scanner(System.in);
operation = r.nextInt();
switch (operation) {
case 1:
// الكود نفسه من التمارين السابقة
* TODO: تحقق من رقم الطالب المُعطى
وقم بإنشاء Student-Object جديد
فقط في حال كان رقم الطالب صالح
*/
break;
case 2:
// الكود نفسه من التمارين السابقة
break;
case 3:
/* TODO
a) اطلب رقم الطالب
b) أعط معلومات الطالب على الشاشة أو رسالة خطأ في حال عدم تواجده
*/
break;
case 4:
// لاحقا
break;
case 5:
/* TODO
a) اطلب رقم الطالب
b) احذف الطالب من النظام أو أعط رسالة خطأ حال عدم تواجده
*/
break;
case 6:
/* TODO
a) اطلب معلومات المدرس من المستخدم
b) استخدم هذه المعلومات لإنشاء عنصر من صنف المدرس حال عدم تواجده
*/
break;
case 7:
/* TODO
a) أعطِ أسماء وكنى جميع المدرسين المخزنين في النظام
*/
break;
case 8:
/* TODO
a) اطلب اسم وكنية المدرس
b) أعط معلومات المدرس أو رسالة خطأ حال عدم تواجده
*/
break;
case 9:
// spaeter
break;
case 10:
/* TODO
a) اطلب اسم وكنية المدرس
b) احذف المدرس من النظام أو أعط رسالة خطأ حال عدم تواجده
*/
break;
case 11:
/* TODO
a) اطلب معلومات الدرس من المستخدم
b) استخدم هذه المعلومات لإنشاء عنصر من صنف الدرس حال عدم تواجده
*/
break;
case 12:
/* TODO
a) أعط رموز وأسماء جميع الدروس المخزنة على الشاشة
*/
break;
case 13:
/* TODO
a) اطلب رمز الدرس
b) أعط معلومات الدرس أو رسالة خطأ حال عدم تواجده
*/
break;
case 14:
// spaeter
break;
case 15:
/* TODO
a) اطلب رمز الدرس
b) احذف الدرس من النظام أو أعط رسالة خطأ حال عدم تواجده
*/
break;
}
}
}
}
السؤال الرابع
قم بتطوير برنامجك السابق بحيث يشتمل على المهام التالية:
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Universitaet uni = new Universitaet();
int operation = 0;
while (operation != 16) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
System.out.println("6- add a Lecturer");
System.out.println("7- view the Lecturers ");
System.out.println("8- search Lecturer");
System.out.println("9- edit Lecturer info");
System.out.println("10- delete Lecturer");
System.out.println("11- add Lesson");
System.out.println("12- view the Lessons");
System.out.println("13- search Lesson");
System.out.println("14- edit Lesson info");
System.out.println("15- delete Lesson");
System.out.println("16- register a Student to a Lesson");
System.out.println("17- asseign Levturer to Lesson");
System.out.println("18- view All the Lessons for a Student");
System.out.println("19- view All the Lessons for a Lecturer");
System.out.println("20- view All Students who registered to a Lesson ");
System.out.println("21- view All Lecturers who assigned to a Lesson");
System.out.println("22- End Programm");
Scanner r = new Scanner(System.in);
operation = r.nextInt();
switch (operation) {
// old Operations + the new Operations from 16 to 21
}
}
}
}
الحلول
ملاحظة: يرجى الانتباه إلى أنه في الحلول أدناه المقصود بـ students_number هو عدد الطلاب ككل، بينما student_number هو رقم الطالب الجامعي.
حل السؤال الأول
Main.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
package myproject;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
University uni = new University("tau", 1000);
int operation = 0;
Scanner r = new Scanner(System.in);
while (operation != 6) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
operation = r.nextInt();
switch (operation) {
case 1:
System.out.println("Enter the Name of Student:");
String a = r.next();
System.out.println("Enter the Surname of Student:");
String b = r.next();
System.out.println("Enter the Student Number:");
String c = r.next();
Student s1 = new Student(a,b,c);
uni.addstudent(s1);
break;
case 2:
uni.allStudents();
break;
}
}
}}
Student.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
package myproject;
public class Student {
String name = "";
String surname = "";
String student_number = "";
public Student(String n, String p, String k) {
name = n;
surname = p;
student_number = k;
}
}
University.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
package myproject;
public class University {
private String name = "";
private String adress = "";
private Student[] my_students;
private int students_number = 0;
public University(String n, int s) {
name = n;
my_students = new Student[s];
}
public void setAdress(String s) {
adress = s;
}
public String getName() {
return name;
}
void addstudent(Student p) {
my_students[students_number] = p;
students_number = students_number + 1;
}
public void allStudents() {
for (int i=0; i < students_number; i++) {
Student p = my_students[i];
System.out.println(p.name + " " + p.surname + " " + p.student_number);
}
}
}
حل السؤال الثاني
Main.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
package myproject;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
University uni = new University("tau");
uni.setAdress("Beykoz");
Scanner r = new Scanner(System.in);
int operation = 1;
while (operation != 3) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- End Programm");
operation = r.nextInt();
if (operation == 1){
System.out.println("Enter the Name of Student:");
String a = r.next();
System.out.println("Enter the Surname of Student:");
String b = r.next();
System.out.println("Enter the Student Number:");
String c = r.next();
Student s1 = new Student(a,b,c);
if(uni.my_students.contains(s1) == false){
uni.my_students.add(s1);
}
else{
System.out.println("Student already exists");
}
}
else if(operation == 2){
uni.allStudents();
}
else{
System.out.println("Enter a valid operation number");
}
}
}
}
Student.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
67
68
69
70
71
72
73
74
75
76
package myproject;
public class Student {
private String name = "unknown";
private String nachname = "unknown";
private String student_number;
private String id = "111111111111";
private int birthdate = 2000;
private double average = 2.0;
private int class = 1;
private String telephon = "5555555555";
private String email = "s@uni.edu";
private String adress = "Global";
public Student(String n, String p, String k) {
name = n;
surname = p;
student_number = k;
}
public Student(String n, String p) {
name = n;
student_number = p;
}
public Student(String n, int p, int k) {
student_number = n;
birthdate = p;
class = k;
}
@Override
public String toString(){
return student_number + ", " + name + " " + surname.toUpperCase();
}
public boolean equals(Object o) {
Student p = (Student) o;
if (student_number.equals(p.student_number)) {
return true;
}
return false;
}
}
University.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
package myproject;
import java.util.Vector;
public class University {
private String name = "uni";
private String adress = "Global";
Vector my_students = new Vector();
private int students_number = 1;
public University(String n) {
name = n;
}
public void setAdress(String s) {
adress = s;
}
public String getName() {
return name;
}
public void allStudents() {
students_number = my_students.size();
System.out.println(my_students);
}
}
حل السؤال الثالث
Main.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package myproject;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
University uni = new University("tau");
uni.setAdresse("Beykoz");
Scanner r = new Scanner(System.in);
int operation = 0;
while (operation != 16) {
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
System.out.println("6- add a Lecturer");
System.out.println("7- view the Lecturers ");
System.out.println("8- search Lecturer");
System.out.println("9- edit Lecturer info");
System.out.println("10- delete Lecturer");
System.out.println("11- add Lesson");
System.out.println("12- view the Lessons");
System.out.println("13- search Lesson");
System.out.println("14- edit Lesson info");
System.out.println("15- delete Lesson");
System.out.println("16- End Programm");
operation = r.nextInt();
switch (operation){
case 1:
System.out.println("Enter the Name:");
String a = r.next();
System.out.println("Enter the Surname:");
String b = r.next();
System.out.println("Enter the Student Number:");
String c = r.next();
if (Student.test(c)){
System.out.println("the Student Number is not valid");
break;
}
Student s1 = new Student(a,b,c);
if(uni.my_students.contains(s1) == false){
uni.my_students.add(s1);
break;
}
else{
System.out.println("Student already exist");
break;
}
case 2:
uni.allStudents();
break;
case 3:
System.out.println("Enter the Student Number");
String u = r.next();
Student s2 = new Student(u);
uni.search(s2);
break;
case 4:
//later
break;
case 5:
System.out.println("Enter the Student Number");
String u1 = r.next();
Student s3 = new Student(u1);
uni.delete(s3);
break;
case 6:
System.out.println("Enter the Name:");
String a2 = r.next();
System.out.println("Enter the Surname:");
String b2 = r.next();
Lecturer d1 = new Lecturer(a2,b2);
if(uni.my_lecturers.contains(d1) == false){
uni.my_lecturers.add(d1);
break;
}
else{
System.out.println("Lecturer already exist");
break;
}
case 7:
uni.allLecturers();
break;
case 8:
System.out.println("Enter the Name:");
String u2 = r.next();
System.out.println("Enter the Surname:");
String u3 = r.next();
Lecturer d2 = new Lecturer(u2,u3);
uni.searchD(d2);
break;
case 9:
//later
break;
case 10:
System.out.println("Enter the Name:");
String u4 = r.next();
System.out.println("Enter the Surname:");
String u5 = r.next();
Lecturer d3 = new Lecturer(u4,u5);
uni.deleteD(d3);
break;
case 11:
System.out.println("Enter the Code of the Lesson:");
String l = r.next();
System.out.println("Enter the Name of the Lesson:");
String l1 = r.next();
Lesson l3 = new Lesson(l,l1);
if(uni.lesson.contains(l3) == false){
uni.lesson.add(l3);
break;
}
else{
System.out.println("Lesson already exist");
break;
}
case 12:
uni.allLessons();
break;
case 13:
System.out.println("Enter the Code of the Lesson:");
String l4 = r.next();
LVA l5 = new Lesson(l4);
uni.searchL(l5);
break;
case 14:
//later
break;
case 15:
System.out.println("Enter the Code of the Lesson:");
String l6 = r.next();
Lesson l7 = new Lesson(l6);
uni.deleteL(l7);
break;
}
}
}}
Student.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package myproject;
public class Student extends Person {
private String student_number;
private double average = 2.0;
private int class_num = 1;
public Student(String n, String p, String k) {
name = n;
surname = p;
student_number = k;
}
public Student(String n, String p) {
name = n;
student_number = p;
}
public Student(String n, int p, int k) {
student_number = n;
birthdate = p;
class_num = k;
}
public Student(String m){
student_number = m;
}
@Override
public String toString(){
return student_number + ", " + name + " " + surname.toUpperCase();
}
public boolean equals(Object o) {
Student p = (Student) o;
if (student_number.equals(p.student_number)) {
return true;
}
return false;
}
public static boolean test(String c){
boolean numeric = false;
try{
int k = Integer.valueOf(c);
}
catch(java.lang.NumberFormatException e){
numeric = true;
}
if (c.startsWith("0") || c.length()!=7 || numeric){
return true;
}
else{
return false;
}
}
}
University.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
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
package myproject;
import java.util.Vector;
public class University {
private String name = "uni";
private String adress = "Global";
Vector<Student> my_students = new Vector();
Vector<Lecturer> my_lecturers = new Vector();
Vector<Lecture> lecture = new Vector();
private int studetns_number = 1;
public University(String n) {
name = n;
}
public void setAdress(String s) {
adress = s;
}
public String getName() {
return name;
}
public void allStudents() {
if (my_students.size() == 0){
System.out.println("There's no students till now");
}
else{
for (int i = 0; i < my_students.size(); i ++){
Student s = (Student) my_students.get(i);
System.out.println(s);
}}
}
public void allLecturers() {
if (my_lecturers.size() == 0){
System.out.println("There's no lecturers till now");
}else{
for (int i = 0; i < my_lecturers.size(); i ++){
Lecturer s = (Lecturer) my_lecturers.get(i);
System.out.println(s);
}}
}
public void allLectures() {
if (lecture.size() == 0){
System.out.println("There's no lectures till now");
}
else{
for (int i = 0; i < lecture.size(); i++){
Lecture s = (Lecture) lecture.get(i);
System.out.println(s);
}}
}
public void search(Student s1){
if (my_students.contains(s1)) {
int e = my_students.indexOf(s1);
System.out.println("Student exists, his Informations are: ");
System.out.println(my_students.elementAt(e));
}else{
System.out.println("Student not found");
}
}
public void searchD(Lecturer s1){
if (my_lecturers.contains(s1)) {
int e = my_lecturers.indexOf(s1);
System.out.println("Lecturer exists, his Informations are:");
System.out.println(my_lecturers.elementAt(e));
}else{
System.out.println("Lecturer not found");
}
}
public void searchL(Lecture s1){
if (lecture.contains(s1)) {
int e = lecture.indexOf(s1);
System.out.println("Lecture exists, its Informations are:");
System.out.println(lecture.elementAt(e));
}else{
System.out.println("Lecture not found");
}
}
public void delete(Student s1){
if (my_students.contains(s1)) {
int e = my_students.indexOf(s1);
System.out.println("Student will be deleted..");
my_students.remove(e);
}else{
System.out.println("Student not found");
}
}
public void deleteD(Lecturer s1){
if (my_lecturers.contains(s1)) {
int e = my_lecturers.indexOf(s1);
System.out.println("Lecturer will be deleted..");
my_lecturers.remove(e);
}else{
System.out.println("Lecturer not found");
}
}
public void deleteL(Lecture s1){
if (lecture.contains(s1)) {
int e = lecture.indexOf(s1);
System.out.println("Lecture will be deleted..");
lecture.remove(e);
}else{
System.out.println("Lecture not found");
}
}
}
Person.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
package myproject;
/**
*
* @author mulham.github.io
*/
public class Person {
protected String name = "unknown";
protected String surname = "unkown";
protected String id = "111111111111";
protected int birthdate = 2000;
protected String telephon = "5555555555";
protected String email = "s@uni.edu";
protected String adress = "Global";
}
Lecture.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
package myproject;
/**
*
* @author mulham.github.io
*/
public class Lecture {
private String Code;
private String Name;
public Lecture(String a, String b){
Code = a;
Name = b;
}
public Lecture(String a){
Code = a;
}
@Override
public String toString(){
return Code.toUpperCase() + " " + Name;
}
public boolean equals(Object o) {
Lecture p = (Lecture) o;
if (Code.equals(p.Code)) {
return true;
}
return false;
}
}
Lecturer.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
package myproject;
/**
*
* @author mulham.github.io
*/
public class Lecturer extends Person {
public Lecturer(String n, String p) {
name = n;
surname = p;
}
public Lecturer(String n) {
name = n;
}
@Override
public String toString(){
return name + " " + surname.toUpperCase();
}
public boolean equals(Object o) {
Lecturer p = (Lecturer) o;
if (name.equals(p.name)) {
return true;
}
return false;
}
}
حل السؤال الرابع
Main.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
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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Student koro = new Student("3216547", "mm", "n");
File f = new File("/home/Dokumente/asdfg.txt");
Uni TAU = new Uni();
Lecturer d = new Lecturer("","","");
Course k = new Course(0,"");
int operation = 0;
while (operation !=22) {
System.out.println("Welche Operation moechten Sie durchfuehren?");
System.out.println("What Operation do you want to do?");
System.out.println("1- add Student");
System.out.println("2- view Students");
System.out.println("3- search Student");
System.out.println("4- edit Student info");
System.out.println("5- delete Student");
System.out.println("6- add a Lecturer");
System.out.println("7- view the Lecturers ");
System.out.println("8- search Lecturer");
System.out.println("9- edit Lecturer info");
System.out.println("10- delete Lecturer");
System.out.println("11- add Lesson");
System.out.println("12- view the Lessons");
System.out.println("13- search Lesson");
System.out.println("14- edit Lesson info");
System.out.println("15- delete Lesson");
System.out.println("16- register a Student to a Lesson");
System.out.println("17- asseign Levturer to Lesson");
System.out.println("18- view All the Lessons for a Student");
System.out.println("19- view All the Lessons for a Lecturer");
System.out.println("20- view All Students who registered to a Lesson ");
System.out.println("21- view All Lecturers who assigned to a Lesson");
System.out.println("22- End Programm");
Scanner sc = new Scanner(System.in);
try {
operation = sc.nextInt();
}catch(InputMismatchException inp) {
}catch(NumberFormatException num) {
}
switch (operation) {
case 1 :
TAU.addStudent();
break;
case 2 :
TAU.listAllStudents();
break;
case 3 :
TAU.searchStudent();
break;
case 4 :
TAU.editStudent();
break;
case 5 :
TAU.deleteStudent();
break;
case 6 :
TAU.addDozient();
break;
case 7:
TAU.listAlleLecturers();
break;
case 8 :
TAU.searchDozient();
break;
case 9 :
TAU.editDozient();
break;
case 10 :
TAU.deletDozient();
break;
case 11 :
TAU.addLVA();
break;
case 12:
TAU.listAllCourses();
break;
case 13:
TAU.searchCourses();
break;
case 14:
TAU.editCourses();
break;
case 15:
TAU.delCourses();
break;
case 16 :
TAU.studzuCourses();
break;
case 17 :
TAU.LehrerzuCourses();
break;
case 18 :
TAU.listLVAderStudent();
break;
case 19 :
TAU.listLVAderDozent();
break;
case 20 :
TAU.listStudentsderCourses();
break;
case 21 :
TAU.listDozentenderCourses();
break;
}
}
}
}
Person.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
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
import java.util.*;
import java.util.Calendar;
public class Person {
protected String name = "";
protected String nickname = "";
protected boolean Geschlecht = true ; // الجنس
protected String Address = "";
protected Calendar birthday = Calendar.getInstance();
protected int age ;
public static boolean isNumeric(String str)
{
for (char c : str.toCharArray())
{
if (!Character.isDigit(c)) return false;
}
return true;
}
public void setName() {
System.out.println("Enter the Name please ");
Scanner sc = new Scanner (System.in);
String a =sc.nextLine();
if (a!="") {
this.name =a;
}
}
public String getName() {
return this.name;
}
public void setNickname() {
System.out.println("Enter the Nickname please ");
Scanner scnachname = new Scanner (System.in);
this.nickname = scnachname.nextLine().toUpperCase();
}
public String getNickname() {
return this.nickname;
}
public void setGeschlecht() {
try {
System.out.println("Enter flase for Man and true form Woman ");
Scanner sc = new Scanner (System.in);
this.Geschlecht = sc.nextBoolean();
}catch (InputMismatchException e) {
System.out.println("the answer should be false or true");
System.out.println("it will be saved as woman = true");
}
}
public boolean getGeschlecht() {
return this.Geschlecht;
}
public void showGeschlecht() {
if (this.Geschlecht==true) {
System.out.println("Geschlecht : woman ");
}
else if(this.Geschlecht == false) {
System.out.println("Geschlecht : Man");
}
}
public void setAddress() {
System.out.println("Please Enter the Address ");
Scanner sc = new Scanner (System.in);
this.Address = sc.nextLine();
}
public String getAddress() {
return this.Address;
}
public void setGeburtstag() {
try {
Scanner sc = new Scanner (System.in);
System.out.println("Enter the Day as a Number from 1 to 31 ! ");
int date = Integer.parseInt(sc.nextLine());
System.out.println("Enter the Month as a Number from 1 to 12 ! ");
int month = Integer.parseInt(sc.nextLine()); // 0 is January. 11 is December.
System.out.println("Enter the Year please! ");
int year = Integer.parseInt(sc.nextLine());
birthday = birthday.getInstance();
birthday.set(year,month,date);
this.age = this.birthday.compareTo(Calendar.getInstance());
}catch(InputMismatchException e) {
System.out.println("Wrong Input, the date of today will be saved");
birthday = birthday.getInstance();
}catch(NumberFormatException t) {
System.out.println("Wrong Input, the date of today will be saved");
}
}
public Calendar getGeburtstag() {
return this.birthday;
}
public void setAge() {
this.age = this.birthday.compareTo(Calendar.getInstance());
}
public int getAge() {
return this.age;
}
}
Student.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import java.lang.String;
//import org.apache.commons.codec.binary.StringUtils;
import java.util.Scanner;
import java.util.Calendar;
import java.util.Vector;
import java.util.*;
public class Student extends Person{
private Calendar JndUniAt = Calendar.getInstance();
private String StudentNumber = "0";
private String Studiumgang = ""; //Course of study or study field
private boolean Scholarship = true;
public boolean Active = true;
private Vector <Course> LectureOfStudent = new Vector<Course>(0);
public boolean equals(Object o) {
Student s = (Student) o;
if (this.StudentNumber.equals(s.StudentNumber)==true) {
return true;
}else {
return false;
}
}
//////// to String
public String toString() {
return"Nickname : "+this.nickname +" Name : "+this.name +" StudentNumber "+ this.StudentNumber;
}
public Student (String a) {
this.StudentNumber= a;
}
public Student (String a, String b, String c) {
this.StudentNumber = a;
this.nickname = c;
this.name = b;
}
public String getMartknummer() {
return this.StudentNumber;
}
public String inmtrklnummer() {
Scanner sc = new Scanner (System.in);
System.out.println("the StudentNumber contains 7 Numbers and should not be 0.");
return sc.nextLine();
}
public static boolean chkmtrklnmr(String a) {
if((a.toCharArray().length==7)&&(a.charAt(0)!='0')) {
return true;
}else if(a.toCharArray().length!=7) {
System.out.println("Wrong Input, try again..");
System.out.println("the StudentNumber contains 7 Numbers.");
return false;
}else {
return false;
}
}
public void setmrtknummer(String str) {
this.StudentNumber = str;
}
public void setActive() {
Scanner scanner = new Scanner (System.in);
try {
if (this.Geschlecht == true ) {
System.out.println("when the Student is Active, Enter true , otherwise false ! ");
} else {
System.out.println("when the Student is Active, Enter true , otherwise false !");
}
this.Active = scanner.nextBoolean();
} catch(InputMismatchException e) {
}
}
public boolean getistActive() {
return this.Active;
}
/////////
public void setStudiumGang() {
System.out.println("please enter the Course of study .");
Scanner sc = new Scanner(System.in);
this.Studiumgang = sc.nextLine();
}
public String getStudiumGang() {
return this.Studiumgang;
}
///////////////
public void hasScholarship() {
try {
if (this.Geschlecht == true ) {
System.out.println("Has the Student a Scholarship?");
} else {
System.out.println("Has the Student a Scholarship?");
}
Scanner scanner = new Scanner (System.in);
this.Scholarship = scanner.nextBoolean();
}catch(InputMismatchException v) {
System.out.println("your answer should be true or false");
System.out.println("Saved : Student has no Scholarship.");
}
}
public boolean getScholarship() {
return this.Scholarship;
}
public void joinUni() {
this.JndUniAt = Calendar.getInstance();
}
public void editJoinedUni() {
try {Scanner sc = new Scanner (System.in);
/*
* int date = sc.nextInt(); int month = sc.nextInt(); int year = sc.nextInt();
*/
System.out.println("Enter the Day as a Number from 1 to 31 ! ");
int date = Integer.parseInt(sc.nextLine());
System.out.println("Enter the Month as a Number from 1 to 12 ! ");
int month = Integer.parseInt(sc.nextLine()); // 0 ist Januar. 11 ist Dezember.
System.out.println("Enter the Year please! ");
int year = Integer.parseInt(sc.nextLine());
this.JndUniAt.set(year, month, date);
} catch (InputMismatchException e) {
System.out.println("Wrong Input ");
System.out.println("the date will not be changed");
}
}
public void addLVA(Course l) {
this.LectureOfStudent.add(l);
}
public void listLVA() {
try {
Enumeration e = this.LectureOfStudent.elements();
while (e.hasMoreElements()) {
System.out.println(e.nextElement());
}
}catch(NoSuchElementException no) {
System.out.println("LVA Liste ist leer..");
}
}
public void delLecture() {
this.listLVA();
if(this.LectureOfStudent.isEmpty()==false) {
Lecturer d = new Lecturer("","","");
Course le = new Course(0,"");
System.out.println("Please Enter the Code of the Course..");
le.setCode();
if(this.LectureOfStudent.contains(le)==true) {
this.LectureOfStudent.remove(le);
}else if(this.LectureOfStudent.contains(le)==false) {
System.out.println("the Student isn't taking this Course");
}
}else {
System.out.println("can not be deleted..");
}
}
public void delthisLVA(Course g ) {
if(this.LectureOfStudent.contains(g)==true) {
this.LectureOfStudent.remove(g);
}
}
}
Uni.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
import java.util.Vector;
import java.util.*;
import java.util.Scanner;
public class Uni {
private Vector<Student> Students = new Vector<Student>(0);
private Vector<Lecturer> Lecturers = new Vector<Lecturer>(0);
private Vector<Course> Courses = new Vector<Course>(0);
//index is always i+1
//Students
public void addStudent () {
Scanner sc = new Scanner(System.in);
Student a = new Student ("0" , "","" );
boolean operation = false;
String str = a.inmtrklnummer();
if(a.chkmtrklnmr(str)==true) {
a.setmrtknummer(str);
}else {
a.setmrtknummer("0");
}
////////////////gibt es bereits ??
if ((Students.contains(a)==true)||(a.getMartknummer()=="0")) {
operation = false;
if (Students.contains(a)==true) {
System.out.println("a Student with this Student Number already exists! ");
}else {
}
}else {
operation = true;
System.out.println("processing..");
}
if (operation == true) {
a.setNickname();
a.setName();
a.setGeschlecht();
System.out.println("Please enter the Birthday..");
a.setGeburtstag();
a.setStudiumGang();
a.setAddress();
a.hasScholarship();
a.joinUni();
Students.add(a);
}
}
public void editStudent() {
//Student a = new Student(0,"","");
//das Element waehlen
//Vector<Student> vec = new Vector<Student>();
/*vec = Students;
vec.toString();*/
Scanner sc = new Scanner (System.in);
int z = Students.indexOf(Students.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Students.elementAt(i) );///work
}
System.out.println("Enter the Index of Student Please!");
try {
int index = sc.nextInt()-1;
Object b = (Students.get(index));
Student a = new Student("0","","");
a = (Student ) b ;
if (Students.get(index).getGeschlecht()==true) {
System.out.println("The called Student is:");
}else {
System.out.println("The called Student is: ");
}
System.out.println(a);
//
int operation =0;
while (operation !=10) {
System.out.println("what do you want to edit?");
System.out.println("Please Enter the Number of Process");
System.out.println("1 = The Name");
System.out.println("2 = The Nickname");
System.out.println("3 = The Gender");
System.out.println("4 = Address");
System.out.println("5 = Birthday");
System.out.println("6 = Scholarship Status ");
System.out.println("7 = Course of study ");
System.out.println("Enter 8 for Student List.");
System.out.println("Enter 9 to save and close");
System.out.println("0 to close without saving");
Scanner vs= new Scanner(System.in);
int s = vs.nextInt();
if(s == 0) {
operation =10;
}else {
operation = s;
switch (operation) {
case 1 ://vorname
a.setName();
break;
case 2 :
a.setNickname();
break;
case 3 :
a.setGeschlecht();
break;
case 4 :
a.setAddress();
break;
case 5 :
a.setGeburtstag();
break;
case 6:
a.hasScholarship();
break;
case 7:
a.setStudiumGang();
break;
case 8:
z = Students.indexOf(Students.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Students.elementAt(i) );///arbeit
}
System.out.println("Please Enter the Index of the Student!");
break;
case 9 :
Students.set(index, a);
operation =10;
break;
}
}
}
}catch(ArrayIndexOutOfBoundsException p ) {
System.out.println("Wrong Input, try again.");
}catch(InputMismatchException i) {
System.out.println("Wrong Input, try again.");
}
}
public void listAllStudents() {
try {
int z = Students.indexOf(Students.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Students.elementAt(i) );///arbeit
}
}catch(NoSuchElementException o){
System.out.println("No Students was found, the list is empty!");
}
}
public void searchStudent() {
Scanner v = new Scanner (System.in);
System.out.println("searching with Student nUmber.");
Student a = new Student("0","","");
String str = a.inmtrklnummer();
if(a.chkmtrklnmr(str)==true) {
a.setmrtknummer(str);
if (Students.contains(a)==true) {
//int z = Students.indexOf(Students.lastElement());
//for(int i =0; i<=z;i++){
int i =Students.indexOf(a);
//if (Students.get(i).equals(a)==true) {
System.out.println("Index :"+(i+1)+" "+Students.elementAt(i) );
System.out.println("a Student with this Number was found: ");
System.out.println("Index : " + (i+1) + Students.get(i));
System.out.println("Index : " + (i+1) + Students.get(i));
System.out.println("Address : "+Students.get(i).getAddress());
System.out.println("Active : "+Students.get(i).getistActive());
System.out.println("Age : "+Students.get(i).getAge());
System.out.println("Birthday : "+Students.get(i).getGeburtstag().DATE+"/"+Students.get(i).getGeburtstag().MONTH+"/"+Students.get(i).getGeburtstag().YEAR);
System.out.println("Course of Study : "+Students.get(i).getStudiumGang());
System.out.println("Has Scholarship : "+Students.get(i).getScholarship());
//}
//}
}
}else {
System.out.println("Wrong Input.");
}
}
public void deleteStudent() {
Scanner v = new Scanner (System.in);
System.out.println("searching.");
Student a = new Student("","","");
String str = v.nextLine();
if (a.chkmtrklnmr(str)==true) {
a.setmrtknummer(str);
}else {
a.setmrtknummer("0");
System.out.println("Wrong Input..");
}
if(Students.isEmpty()==false) {
if (Students.contains(a)==true) {
int z = Students.indexOf(Students.lastElement());
int i =0;
for( i =0; i<=z;i++){
if (Students.get(i).equals(a)==true) {
//System.out.println("Index :"+(i+1)+" "+Students.elementAt(i) );
System.out.println("a Student with this Number is found: ");
System.out.println("Index : " + (i+1) + Students.get(i));
System.out.println("Do you want really to delete this Student from list?");
a=Students.get(i);
break;
}
}
Scanner del = new Scanner (System.in);
String ans= del.nextLine();
if((ans.equals("yes"))||(ans.equals("yes"))||(ans.equals("yes"))||(ans.equals("evet"))||(ans.equals("EVET"))||(ans.equals("Evet"))) {
Students.remove(i);
int in=0;
do {
Courses.elementAt(in).delLernend(a);
}while(in<Courses.indexOf(Courses.lastElement()));
System.out.println("Deleting Student..");
}
}/*gibt es nicht...*/else {
System.out.println("No Student is found!");
//System.out.println("No Student is found!");
}
}else {
System.out.println("No saved Students...");
}
}
//Lecturers
public void addDozient() {
Lecturer a = new Lecturer("","","");
System.out.println("Please enter the Name and Nickname");
a.setNickname();
a.setName();
if (Lecturers.contains(a)==false) {
//a.setPrsnlnummer();
a.setGeschlecht();
System.out.println("Please Enter the Birthday");
a.setGeburtstag();
a.setAddress();
a.joinUni();
a.setTitel();
a.setField();
Lecturers.add(a);
}else {
if(Lecturers.contains(a)==true) {
System.out.println("a Lecturer with this Number already exists! ");
}
else {
}
}
}
public void editDozient() {
Scanner sc = new Scanner (System.in);
int z = Lecturers.indexOf(Lecturers.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Lecturers.elementAt(i) );///arbeit
}
//System.out.println("Bitte den Index Des Dozent*In Eingeben ");
//umformen
try {
Lecturer a = new Lecturer("","","");
a.setName();
a.setNickname();
int index =0;
for(index=0;index<=Lecturers.capacity();index++) {
if(Lecturers.get(index).equals(a)) {
break;
}
}
Object b = (Lecturers.get(index));
a = (Lecturer) b ;
System.out.println("the returned Lecturer is :");
System.out.println(a);
//
int operation =0;
while (operation !=10) {
System.out.println("what do you want to edit?");
System.out.println("Please enter the number of wanted Process");
System.out.println("1 = Name");
System.out.println("2 = Nickname");
System.out.println("3 = Genre");
System.out.println("4 = Address");
System.out.println("5 = Birthday");
System.out.println("6 = Titel ");
System.out.println("7 = Field");
System.out.println("Enter 8 for Student List.");
System.out.println("Enter 9 to save and close");
System.out.println("0 to close without saving");
Scanner vs= new Scanner(System.in);
int s = vs.nextInt();
if(s == 0) {
operation =10;
}else {
operation = s;
switch (operation) {
case 1 ://vorname
a.setName();
break;
case 2 :
a.setNickname();
break;
case 3 :
a.setGeschlecht();
break;
case 4 :
a.setAddress();
break;
case 5 :
a.setGeburtstag();
break;
case 6://titel
a.setTitel();;
break;
case 7://fach
a.setField();;
break;
case 8:
z = Lecturers.indexOf(Lecturers.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Lecturers.elementAt(i) );///arbeit
}
System.out.println("Please Enter the Index of Lecturer !");
break;
case 9 :
Lecturers.set(index, a);
operation =10;
break;
}
}
}
}catch(ArrayIndexOutOfBoundsException p ) {
System.out.println("Wrong Input,try again.");
System.out.println("the list is from 1 to "+Lecturers.capacity());
}catch(InputMismatchException i) {
System.out.println("Wrong Input,try again.");
}catch(NoSuchElementException k) {
System.out.println("Wrong Input,try again.");
}
}
public void searchDozient() {
Scanner v = new Scanner (System.in);
System.out.println("searching.");
Lecturer a = new Lecturer("","","");
a.setNickname();
a.setName();
if (Lecturers.contains(a)==true) {
int z = Lecturers.indexOf(Lecturers.lastElement());
for(int i =0; i<=z;i++){
if (Lecturers.get(i).equals(a)==true) {
System.out.println("Index :"+(i+1)+Lecturers.get(i).getTitel()+" "+Lecturers.elementAt(i) );
System.out.println("a lecturer was found: ");
System.out.println("Titel : "+Lecturers.get(i).getTitel());
System.out.println( Lecturers.get(i)+"Index : " + (i+1));
System.out.println("Address : "+Lecturers.get(i).getAddress());
System.out.println("Age : "+Lecturers.get(i).getAge());
System.out.println("Birthday : "+Lecturers.get(i).getGeburtstag().DATE+"/"+Lecturers.get(i).getGeburtstag().MONTH+"/"+Lecturers.get(i).getGeburtstag().YEAR);
System.out.println("Field : "+Lecturers.get(i).getField());
System.out.println("Joined uni at : "+Lecturers.get(i).joinedUniAt().DATE+"/"+Lecturers.get(i).joinedUniAt().MONTH+"/"+Lecturers.get(i).joinedUniAt().YEAR);
}
}
}
else {
System.out.println("No Lecturer eas found!");
}
}
public void listAlleLecturers() {
try {
int z = Lecturers.indexOf(Lecturers.lastElement());
for(int i =0; i<=z;i++){
System.out.println("Index :"+(i+1)+" "+Lecturers.elementAt(i) );///arbeit
}
}catch(NoSuchElementException p) {
System.out.println("No Lecturer was found, the list is emoty!");
}
}
public void deletDozient() {
Scanner v = new Scanner (System.in);
System.out.println("searching by name and nickname..");
Lecturer a = new Lecturer("","","");
a.setNickname();
a.setName();
if (Lecturers.contains(a)==true) {
int z = Lecturers.indexOf(Lecturers.lastElement());
int i =0;
for( i =0; i<=z;i++){
if (Lecturers.get(i).equals(a)==true) {
//System.out.println("Index :"+(i+1)+" "+Lecturers.elementAt(i) );
System.out.println("a Lecturer was found : ");
System.out.println("Index : " + (i+1) + Lecturers.get(i));
System.out.println("Do you really want to delete this Lecturer ?");
a=Lecturers.get(i);
break;
}
}
Scanner del = new Scanner (System.in);
String ans= del.nextLine();
if((ans.equals("yes"))||(ans.equals("yes"))||(ans.equals("yes"))||(ans.equals("evet"))||(ans.equals("EVET"))||(ans.equals("Evet"))) {
Lecturers.remove(i);
int in=0;
do {
Courses.elementAt(in).delLecturer(a);
}while(in<Courses.indexOf(Courses.lastElement()));
System.out.println("deleting Lecturer..");
}
}/*gibt es nicht...*/else {
System.out.println("No Lecturer was found!");
}
}
//LA
public void addLVA(){
Lecturer a = new Lecturer("","","");
Course l = new Course(0,"");
Student stud = new Student("0","","");
Scanner sc= new Scanner (System.in);
String choice1 = "";
int index1=0,index2=0,index3 =0;
//setting the code for l
try{
System.out.println("Enter Code of Course");
l.setCode();
}catch(InputMismatchException in){
System.out.println("Wrong Input.");
}
if((Courses.contains(l)==false)&&(l.getCode()!=0)){
//code ist guut...
///set the Lehrer..
System.out.println("Do you want to add new Lecturer now?");
choice1= sc.nextLine();
if((choice1.equals("yes"))||(choice1.equals("yes"))||(choice1.equals("yes"))||(choice1.equals("yes"))) {
//ich will..
do {
// hinfuegen ?? yes..
choice1="yes";
///muss am ende Fragen
String choicestud="";
System.out.println("Do you want to choose from Lecturers List?");
choicestud = sc.nextLine();
///////////von lite waehlen oder neu ? ?????
if(Lecturers.isEmpty()==false) {
if((choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)){
//von liste
index2=0;
int z =Lecturers.indexOf(Lecturers.lastElement());
System.out.println("the existing Lecturers : ");
Lecturer ab = new Lecturer("","","");
do {
System.out.println(Lecturers.elementAt(index2));
index2++;
}while(index2<z);
/*choicestud = sc.nextLine();*/
this.listAlleLecturers();
Scanner v = new Scanner (System.in);
ab.setNickname();
ab.setName();
//gibt es bei uns??
if(Lecturers.contains(ab)==true) {
System.out.println("Lecturer: ");
ab = Lecturers.get(Lecturers.indexOf(ab));
///welche/r ist er / sie?
index2=0;
do{
if(Lecturers.elementAt(index2).equals(ab)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Lecturers.elementAt(index2));
System.out.println("will be added..");
l.setLecturer(Lecturers.elementAt(index2));
System.out.println("Lecturers : "+Lecturers.elementAt(index2)+"added Successfully..");
/////////////erfolg....
}else {
/// es ist nicht in der Liste
//dummmmm.... Thanos must be stopped....
System.out.println("not found..");
System.out.println("Please give more Information");
ab.setNickname();
ab.setName();
ab.setGeburtstag();
ab.setGeschlecht();
ab.setAddress();
Lecturers.add(ab);
l.setLecturer(ab);
System.out.println("Lecturer : "+ab+"added Successfully..");
//////////erfolg...............
}
}else {
//is empty false... and not from list !!!!
System.out.println("Adding new Lecturer..");
Lecturer lecturer1 = new Lecturer("0","","");
lecturer1.setNickname();
lecturer1.setName();
if((Lecturers.contains(lecturer1)==false)&&(lecturer1.getNickname().equals("") ==false)) {
lecturer1.setNickname();
lecturer1.setName();
lecturer1.setAddress();
lecturer1.setGeschlecht();
lecturer1.setGeburtstag();
Lecturers.add(lecturer1);
l.setLecturer(lecturer1);
System.out.println("Lecturer : "+ lecturer1 +"added Successfully..");
}else {
//////Students contains stud.....
int z = Lecturers.indexOf(Lecturers.lastElement());
do{
if(Lecturers.elementAt(index2).equals(lecturer1)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Lecturers.elementAt(index2));
System.out.println("will be added..");
l.setLecturer(Lecturers.elementAt(index2));
System.out.println("Lecturer : "+Lecturers.elementAt(index2)+"added Successfully..");
}
}
}else {
// is empty is true...
System.out.println("Adding new Lecturer..");
Lecturer doz = new Lecturer("","","");
if((Lecturers.contains(doz)==false)) {//edit now
doz.setNickname();
doz.setName();
doz.setAddress();
doz.setGeschlecht();
doz.setGeburtstag();
doz.setTitel();
doz.setField();
Lecturers.add(doz);
l.setLecturer(doz);
System.out.println("Lecturer : "+doz+"added Successfully..");
}else {
//////Dozenten contains doz.....
int z=0;
try {
z = Lecturers.indexOf(Lecturers.lastElement());
do{
if(Lecturers.elementAt(index2).equals(doz)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Lecturers.elementAt(index2));
System.out.println("will be added..");
l.setLecturer(Lecturers.elementAt(index2));
System.out.println("Dozent : "+Lecturers.elementAt(index2)+"added Successfully..");
}catch(NoSuchElementException p) {
System.out.println("Wrong Input.. try again.");
}
}
}
System.out.println("Do you want to add more Lecturers? ");
String antw = "yes";
antw=sc.nextLine();
if((antw.equals("yes")==true)||(antw.equals("yes")==true)||(antw.equals("yes")==true)) {
choice1 = "yes";
}else {
choice1="no";
}
}while(choice1.equals("yes"));
}else {
System.out.println("this Courses has now no Lecturers.. you can add them later.");
//taa daaaa
}
//Lehrer oki...
//fortgehen......
l.setTitel();
l.setField();
l.setPlace();
/////////////alles ist gut bis jetzt...
/////////////aber wir brauchen ein bisschen Students...
////////the reality can be whatever I want... soon will RIP : THANOS
System.out.println("Do you want to add Students now?");
choice1 = sc.nextLine();
if((choice1.equals("yes"))||(choice1.equals("yes"))||(choice1.equals("yes"))||(choice1.equals("yes"))) {
//ich will..
do {
// hinfuegen ?? yes..
choice1="yes";
///muss am ende Fragen
String choicestud="";
System.out.println("Do you want to choose from Students List?");
choicestud = sc.nextLine();
///////////von lite waehlen oder neu ? ?????
if(Students.isEmpty()==false) {
if((choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)){
//von liste
index2=0;
int z =Students.indexOf(Students.lastElement());
System.out.println("the existing Students : ");
do {
System.out.println(Students.elementAt(index2));
index2++;
}while(index2<z);
/*choicestud = sc.nextLine();*/
Student student2 = new Student("0","","");
String str = student2.inmtrklnummer();
if(student2.chkmtrklnmr(str)==true) {
student2.setmrtknummer(str);
}else {
student2.setmrtknummer("0");
}
//gibt es bei uns??
if(Students.contains(student2)==true) {
System.out.println("Student: ");
///welche/r ist er / sie?
index2=0;
do{
if(Students.elementAt(index2).equals(student2)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
/////////////erfolg....
}else {
/// es ist nicht in der Liste
//dummmmm.... Thanos must be stopped....
System.out.println("not found..");
System.out.println("Please give more Information");
student2.setNickname();
student2.setName();
student2.setGeburtstag();
student2.setStudiumGang();
student2.setGeschlecht();
student2.setAddress();
student2.hasScholarship();
Students.add(student2);
l.setLernend(student2);
System.out.println("Student : "+student2+"added Successfully..");
//////////erfolg...............
}
}else {
//is empty false... and not from list !!!!
System.out.println("adding new sudents..");
Student student1 = new Student("0","","");
String st = student1.inmtrklnummer();
if(student1.chkmtrklnmr(st)==true) {
student1.setmrtknummer(st);
}else {
student1.setmrtknummer("0");
}
if((Students.contains(student1)==false)&&(student1.getMartknummer().equals("0") ==false)) {
student1.setNickname();
student1.setName();
student1.setAddress();
student1.setGeschlecht();
student1.setGeburtstag();
student1.setStudiumGang();
student1.hasScholarship();
Students.add(student1);
l.setLernend(student1);
System.out.println("Student : "+student1+"added Successfully..");
}else {
//////Students contains stud.....
int z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(student1)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
}
}
}else {
// is empty is true...
//dummmmmm................&&&&&
//ich moechte neue menschen hin..
System.out.println("Adding New Students..");
String ds = stud.inmtrklnummer();
if(stud.chkmtrklnmr(ds)==true) {
stud.setmrtknummer(ds);
}else {
stud.setmrtknummer("0");
}
if((Students.contains(stud)==false)&&(stud.getMartknummer().equals("0")!=true)) {
stud.setNickname();
stud.setName();
stud.setAddress();
stud.setGeschlecht();
stud.setGeburtstag();
stud.setStudiumGang();
stud.hasScholarship();
Students.add(stud);
l.setLernend(stud);
System.out.println("Student : "+stud+"added successfully..");
}else {
//////Students contains stud.....
int z=0;
try {
z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(stud)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
System.out.println("Student : "+Students.elementAt(index2)+"added successfully..");
}catch(NoSuchElementException p) {
System.out.println("wrong Input. try again.");
}
}
}
System.out.println("Do you want to add more Students? ");
String antw = "yes";
antw=sc.nextLine();
if((antw.equals("yes")==true)||(antw.equals("yes")==true)||(antw.equals("yes")==true)) {
choice1 = "yes";
}else {
choice1="no";
}
}while(choice1.equals("yes"));
}else {
System.out.println("this Courses has now no Students.. you can add them later.");
//taa daaaa
}
Courses.add(l);
System.out.println("Courses added successfully..");
}
else if(l.getCode()==0){
//Code war irrgend wie 0
System.out.println("finished.");
//end
}else {
//if Courses.contains(l)==true
// ein nicht vorhande code
System.out.println("this Courses already exist..");
System.out.println("");
//end
}
//////bittttiiiiii yaa baaaa
}
///edit nicht bereit..
public void editCourses() {
try {
Lecturer d = new Lecturer("","","");
Lecturer student = new Lecturer("0","","");
Course l = new Course(0,"");
//
//mit dem Titel und Code der Courses suchen..
//try {
this.listAllCourses();
//System.out.println(this.Courses.capacity());
if(this.Courses.isEmpty()== false){
System.out.println("with Code searching..");
l.setCode();
}else {
System.out.println("can not search");
}
//}catch(NoSuchElementException p) {
//}
if (l.getCode() !=0) {
if(Courses.contains(l)==true) {
System.out.println("Courses will be shown..");
//////element finden
int index=0;
l = Courses.get(Courses.indexOf(l));
System.out.println("Courses :");
System.out.println(l);
System.out.println("Courses field : "+l.getField());
System.out.println("Courses Place :"+l.getPlace());
System.out.println("Students :");
l.showLecturer();
Scanner op = new Scanner (System.in);
int versuch =0;
do {
System.out.println("What do you want to edit ?");
System.out.println("0 : Nothing");
System.out.println("1 : Titel");
System.out.println("2 : Place");
System.out.println("3 : Field");
try {
index = op.nextInt();
}catch(InputMismatchException inp){
System.out.println("Wring Input.. Please use numbers..");
System.out.println("you still have "+(3-versuch)+"try..");
versuch++;
if(versuch==3){
index = 0;
}
switch(index) {
case 1 :
l.setTitel();
System.out.println("Titel changed successfully.");
break;
case 2 :
l.setPlace();
break;
case 3 :
l.setField();
break;
}
}
}while(index != 0);
} else {
System.out.println("can not search without Code :(");
}
}else{
///////code war 0
}
}catch(InputMismatchException m) {
}catch(NoSuchElementException poo) {
System.out.println("Courses List is empty..");
}
}
////edit nicht bereit....
public void listAllCourses() {
try {
int lastelement = Courses.indexOf(Courses.lastElement());
int index=0;
for(index=0;index<=lastelement;index++) {
System.out.println(Courses.get(index));
}
}catch(NoSuchElementException o) {
System.out.println("Courses List is empty..");
}
}
public void searchCourses(){
System.out.println("Searching with Code..");
Lecturer d = new Lecturer("","","");
Course l = new Course(0,"");
Scanner sc = new Scanner(System.in);
//int w=0;
try {
l.setCode();
//w = sc.nextInt();
}catch(InputMismatchException in) {
}
try {
int z = Courses.indexOf(Courses.lastElement());
int index =0;
if(Courses.contains(l)==true) {
do {
if(Courses.elementAt(index).equals(l)) {
l=Courses.elementAt(index);
break;
}
index++;
}while(index<z);
System.out.println("Courses"+l+" found.");
System.out.println("Field : "+l.getField());
System.out.println("Place : "+l.getPlace());
try {
System.out.println("Lecturers : ");
do {
System.out.println(l.getLecturer().elementAt(index));
}while(index<l.getLecturer().indexOf(l.getLecturer().lastElement()));
System.out.println("Students :");
do {
System.out.println(l.getstu().elementAt(index));
}while(index<l.getstu().indexOf(l.getstu().lastElement()));
}catch(NoSuchElementException oid) {
}catch(ArrayIndexOutOfBoundsException dsfsd) {
System.out.println("Has no Lecturers..");
}
}else {
System.out.println("can not be found..");
}
}catch(NoSuchElementException u) {
}
}
public void delCourses() {
System.out.println("searching with code..");
Lecturer d = new Lecturer("","","");
Course l = new Course(0,"");
Scanner sc = new Scanner(System.in);
//int w=0;
if(Courses.isEmpty()==false) {
try {
l.setCode();
//w = sc.nextInt();
}catch(InputMismatchException in) {
}try {
int z = Courses.indexOf(Courses.lastElement());
int index =0;
if(Courses.contains(l)==true) {
do {
if(Courses.elementAt(index).equals(l)) {
l=Courses.elementAt(index);
break;
}
index++;
}while(index<z);
System.out.println("Courses"+l+" found.");
System.out.println("Field : "+l.getField());
System.out.println("Place : "+l.getPlace());
System.out.println("Lecturers : ");
do {
System.out.println(l.getLecturer().elementAt(index));
}while(index<l.getLecturer().indexOf(l.getLecturer().lastElement()));
System.out.println("Students :");
do {
System.out.println(l.getstu().elementAt(index));
}while(index<l.getstu().indexOf(l.getstu().lastElement()));
String ans = "";
System.out.println("Do you really want to delete this courses : " +l+"?");
ans=sc.nextLine();
if((ans.equals("yes")==true)||(ans.equals("yes")==true)||(ans.equals("yes")==true)||(ans.equals("evet")==true)) {
Enumeration <Student> en = l.getstu().elements();
try {
while (en.hasMoreElements()) {
Student s = new Student ("0","","");
s = en.nextElement();
Enumeration <Student> vec = Students.elements();
while(vec.hasMoreElements()) {
Student zw = new Student ("0","","");
zw = vec.nextElement();
if(s.equals(zw)==true) {
zw.delthisLVA(l);
}
}
}
}catch(NoSuchElementException nop) {
}
Enumeration <Lecturer> eno = l.getLecturer().elements();
try {
while (eno.hasMoreElements()) {
Lecturer s = new Lecturer("0","","");
s = eno.nextElement();
Enumeration <Lecturer> vec = Lecturers.elements();
while(vec.hasMoreElements()) {
Lecturer zwi= new Lecturer("0","","");
zwi = vec.nextElement();
if(s.equals(zwi)==true) {
zwi.delthisLVA(l);
}
}
}
}catch(NoSuchElementException nop) {
}
Courses.remove(index);
System.out.println("success.");
}
}else {
System.out.println("could not be found..");
}
}catch(NoSuchElementException u) {
}
}else {
System.out.println("the course list are already empty... :)");
}
}
/////////////
public void listLVAderStudent() {
Student st = new Student("0","","");
String str = st.inmtrklnummer();
if (st.chkmtrklnmr(str)==true) {
st.setmrtknummer(str);
}
if(Students.contains(st)==true) {
st = Students.get(Students.indexOf(st));
st.listLVA();
}else {
System.out.println("no such student exists..");
}
}
public void listLVAderDozent() {
Lecturer st = new Lecturer("0","","");
st.setNickname();
st.setName();
if(Lecturers.contains(st)==true) {
st = Lecturers.get(Lecturers.indexOf(st));
st.listLVA();
}else {
System.out.println("no such Lecturer exists..");
}
}
public void studzuCourses() {
Course l = new Course(0,"");
Student stud = new Student("0","","");
Scanner sc= new Scanner (System.in);
String choice1 = "";
String choicestud = "";
int index1=0,index2=0,index3 =0;
///erstens Courses dann STUD
l.setCode();
if(Courses.contains(l)==true) {
l = Courses.get(Courses.indexOf(l));
}else {
System.out.println("no such Course exists.... will add new one");
l.setField();
l.setPlace();
l.setTitel();
System.out.println("you can add Students and Lecturers later..");
Courses.add(l);
}
System.out.println("Do you want to choose from Students list?");
choicestud = sc.nextLine();
///////////von lite waehlen oder neu ? ?????
if(Students.isEmpty()==false) {
if((choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)){
//von liste
index2=0;
int z =Students.indexOf(Students.lastElement());
System.out.println("the existing Students : ");
do {
System.out.println(Students.elementAt(index2));
index2++;
}while(index2<z);
System.out.println("searching");
/*choicestud = sc.nextLine();*/
Student student2 = new Student("0","","");
String str = student2.inmtrklnummer();
if(student2.chkmtrklnmr(str)==true) {
student2.setmrtknummer(str);
}else {
student2.setmrtknummer("0");
}
//gibt es bei uns??
if(Students.contains(student2)==true) {
System.out.println("Student: ");
///welche/r ist er / sie?
index2=0;
do{
if(Students.elementAt(index2).equals(student2)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
stud.addLVA(l);
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
/////////////erfolg....
}else {
/// es ist nicht in der Liste
//dummmmm.... Thanos must be stopped....
System.out.println("not found..");
System.out.println("Please give more Information");
student2.setNickname();
student2.setName();
student2.setGeburtstag();
student2.setStudiumGang();
student2.setGeschlecht();
student2.setAddress();
student2.hasScholarship();
Students.add(student2);
l.setLernend(student2);
stud.addLVA(l);
System.out.println("Student : "+student2+"added Successfully..");
//////////erfolg...............
}
}else {
//is empty false... and not from list !!!!
System.out.println("adding new student..");
Student student1 = new Student("0","","");
String st = student1.inmtrklnummer();
if(student1.chkmtrklnmr(st)==true) {
student1.setmrtknummer(st);
}else {
student1.setmrtknummer("0");
}
if((Students.contains(student1)==false)&&(student1.getMartknummer().equals("0") ==false)) {
student1.setNickname();
student1.setName();
student1.setAddress();
student1.setGeschlecht();
student1.setGeburtstag();
student1.setStudiumGang();
student1.hasScholarship();
Students.add(student1);
l.setLernend(student1);
stud.addLVA(l);
System.out.println("Student : "+student1+"added Successfully..");
}else {
//////Students contains stud.....
int z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(student1)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
}
}
}else {
// is empty is true...
//dummmmmm................&&&&&
//ich moechte neue menschen hin..
System.out.println("adding new student..");
String ds = stud.inmtrklnummer();
if(stud.chkmtrklnmr(ds)==true) {
stud.setmrtknummer(ds);
}else {
stud.setmrtknummer("0");
}
if((Students.contains(stud)==false)&&(stud.getMartknummer().equals("0")!=true)) {
stud.setNickname();
stud.setName();
stud.setAddress();
stud.setGeschlecht();
stud.setGeburtstag();
stud.setStudiumGang();
stud.hasScholarship();
Students.add(stud);
l.setLernend(stud);
stud.addLVA(l);
System.out.println("Student : "+stud+"added Successfully..");
}else {
//////Students contains stud.....
int z=0;
try {
z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(stud)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
stud.addLVA(l);
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
}catch(NoSuchElementException p) {
System.out.println("Wrong Input.. try again.");
}
}
}
}
public void LehrerzuCourses() {
Course l = new Course(0,"");
Student stud = new Student("0","","");
Scanner sc= new Scanner (System.in);
String choice1 = "";
String choicestud = "";
int index1=0,index2=0,index3 =0;
///erstens Courses dann STUD
l.setCode();
if(Courses.contains(l)==true) {
l = Courses.get(Courses.indexOf(l));
}else {
System.out.println("no such Courses.. will add new");
l.setField();
l.setPlace();
l.setTitel();
Courses.add(l);
}
System.out.println("Do you want to choose from Students list?");
choicestud = sc.nextLine();
///////////von lite waehlen oder neu ? ?????
if(Students.isEmpty()==false) {
if((choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)||(choicestud.equals("yes")==true)){
//von liste
index2=0;
int z =Students.indexOf(Students.lastElement());
System.out.println("the existing Students : ");
do {
System.out.println(Students.elementAt(index2));
index2++;
}while(index2<z);
/*choicestud = sc.nextLine();*/
Student student2 = new Student("0","","");
String str = student2.inmtrklnummer();
if(student2.chkmtrklnmr(str)==true) {
student2.setmrtknummer(str);
}else {
student2.setmrtknummer("0");
}
//gibt es bei uns??
if(Students.contains(student2)==true) {
System.out.println("Student*In: ");
///welche/r ist er / sie?
index2=0;
do{
if(Students.elementAt(index2).equals(student2)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
stud.addLVA(l);
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
/////////////erfolg....
}else {
/// es ist nicht in der Liste
//dummmmm.... Thanos must be stopped....
System.out.println("not found..");
System.out.println("Please give more Information");
student2.setNickname();
student2.setName();
student2.setGeburtstag();
student2.setStudiumGang();
student2.setGeschlecht();
student2.setAddress();
student2.hasScholarship();
Students.add(student2);
l.setLernend(student2);
stud.addLVA(l);
System.out.println("Student : "+student2+"added Successfully..");
//////////erfolg...............
}
}else {
//is empty false... and not from list !!!!
System.out.println("adding new student..");
Student student1 = new Student("0","","");
String st = student1.inmtrklnummer();
if(student1.chkmtrklnmr(st)==true) {
student1.setmrtknummer(st);
}else {
student1.setmrtknummer("0");
}
if((Students.contains(student1)==false)&&(student1.getMartknummer().equals("0") ==false)) {
student1.setNickname();
student1.setName();
student1.setAddress();
student1.setGeschlecht();
student1.setGeburtstag();
student1.setStudiumGang();
student1.hasScholarship();
Students.add(student1);
l.setLernend(student1);
stud.addLVA(l);
System.out.println("Student : "+student1+"added Successfully..");
}else {
//////Students contains stud.....
int z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(student1)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
}
}
}else {
// is empty is true...
//dummmmmm................&&&&&
//ich moechte neue menschen hin..
System.out.println("adding new student..");
String ds = stud.inmtrklnummer();
if(stud.chkmtrklnmr(ds)==true) {
stud.setmrtknummer(ds);
}else {
stud.setmrtknummer("0");
}
if((Students.contains(stud)==false)&&(stud.getMartknummer().equals("0")!=true)) {
stud.setNickname();
stud.setName();
stud.setAddress();
stud.setGeschlecht();
stud.setGeburtstag();
stud.setStudiumGang();
stud.hasScholarship();
Students.add(stud);
l.setLernend(stud);
stud.addLVA(l);
System.out.println("Student : "+stud+"added Successfully..");
}else {
//////Students contains stud.....
int z=0;
try {
z = Students.indexOf(Students.lastElement());
do{
if(Students.elementAt(index2).equals(stud)==true) {
break;
}
index2++;
}while(index2<z) ;
////element ausgewaehlt...
System.out.println(Students.elementAt(index2));
System.out.println("will be added..");
l.setLernend(Students.elementAt(index2));
stud.addLVA(l);
System.out.println("Student : "+Students.elementAt(index2)+"added Successfully..");
}catch(NoSuchElementException p) {
System.out.println("Wrong Input.. try again.");
}
}
}
}
public void listStudentsderCourses() {
System.out.println("Searching with Code ..");
Course l = new Course(0,"");
Scanner sc = new Scanner(System.in);
try {
l.setCode();
}catch(InputMismatchException in) {
}
if(Courses.contains(l)==true) {
l = Courses.get(Courses.indexOf(l));
l.showstu();
}else {
System.out.println("Fault..");
}
}
public void listDozentenderCourses() {
System.out.println("searching with code ..");
Course l = new Course(0,"");
Scanner sc = new Scanner(System.in);
try {
l.setCode();
}catch(InputMismatchException in) {
}
if(Courses.contains(l)==true) {
l = Courses.get(Courses.indexOf(l));
l.showLecturer();
}else {
System.out.println("incorrect..");
}
}
}
Course.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
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
156
import java.util.*;
import java.util.Scanner;
public class Course {
public Course(int a, String b) {
Code = a;
Titel = b;
}
public String toString() {
return " Code "+" "+this.Code+" Titel " + this.Titel;
}
public boolean equals(Object o) {
Lecturer d = new Lecturer("","","");
Course l = new Course(0,"");
l = (Course)o;
if(this.Code==l.Code) {
return true;
}else {
return false;
}
}
private String Place = "";
private String Field = "";
private int Code = 0;
private String Titel = "";
private Vector <Student> stu = new Vector<Student>(0);
private Vector <Lecturer> Lecturer = new Vector<Lecturer>(0);
//private Calendar Zeit = Calendar.getInstance();
public void setLernend(Student a) {
if(stu.contains(a)==false) {
stu.add(a);
a.addLVA(this);
}
else {
System.out.println("the Student already exists..");
}
}
public Vector <Student> getstu() {
return stu;
}
public void showstu() {
Enumeration<Student> e = this.stu.elements();
while(e.hasMoreElements()) {
System.out.println(e.nextElement());
}
}
public void setPlace() {
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter the Place");
this.Place = sc.nextLine();
//sc.close();
}
public String getPlace(){
return this.Place;
}
public void setField() {
Scanner sc = new Scanner(System.in);
System.out.println("what is the Field of this Course?");
this.Field = sc.nextLine();
//sc.close();
}
public String getField(){
return this.Field;
}
public void setCode() {
Scanner sc = new Scanner(System.in);
System.out.println("what is the Code of this Course?");
int code=0;
try {
code = Integer.parseInt(sc.nextLine());
}catch(InputMismatchException i) {
code = 0;
}catch(NumberFormatException num) {
code =0;
}
int temp =1; int length =0;
for(length =0; temp<=code; length++) {
temp = temp*10;
}
if(length==3) {
this.Code = code;
System.out.println("Code will be saved.");
}else {
System.out.println("Code is wrong, it should contain 3 numbers.");
System.out.println("Code will not be saved, try again.");
}
}
public int getCode() {
return this.Code;
}
public void setTitel() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Name of the Course ?");
this.Titel = sc.nextLine();
}
public String getTitel() {
return this.Titel;
}
public void setLecturer(Lecturer a) {
if(Lecturer.contains(a)==false) {
Lecturer.add(a);
a.addLVA(this);
}
else {
System.out.println("This Lecturer already exists..");
}
}
public Vector <Lecturer> getLecturer() {
return Lecturer;
}
public void showLecturer() {
Enumeration<Lecturer> e = this.Lecturer.elements();
while(e.hasMoreElements()) {
System.out.println(e.nextElement());
}
}
public void delLecturer(Lecturer a) {
if(Lecturer.contains(a)==true) {
Lecturer.remove(a);
}
}
public void delLernend(Student a) {
if(stu.contains(a)==true) {
stu.remove(a);
}
}
}
Lecturer.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
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
import java.util.*;
public class Lecturer extends Person {
public Lecturer(String a, String b, String c) {
this.nickname =a ;
this.name =b;
this.Titel = c;
}
private String Titel = "";
//private long Personelnummer=0;
private Calendar JndUniAt = Calendar.getInstance();
private String Field = "";
private Vector<Course> LectrueOfLecturer = new Vector<Course>(0);
public String toString () {
return "Name : "+this.nickname +" Nicknmae : "+ this.name;
}
public boolean equals(Object o) {
Lecturer s = (Lecturer) o;
if ((this.nickname.equals(s.nickname))&&(this.name.equals(s.name))) {
return true;
}else {
return false;
}
}
public void setTitel() {
Scanner sc = new Scanner (System.in);
if (this.Geschlecht == true) {
System.out.println("Please Enter the Titel of the Lecturer.");
}
else {
System.out.println("Please Enter the Titel of the Lecturer.");
}
this.Titel = sc.nextLine();
}
public String getTitel() {
return this.Titel;
}
public void joinUni() {
this.JndUniAt = Calendar.getInstance();
}
public void editJoinedUni() {
Scanner sc = new Scanner (System.in);
/*
* int date = sc.nextInt(); int month = sc.nextInt(); int year = sc.nextInt();
*/
System.out.println("Enter the Day as a Number from 1 to 31 ! ");
int date = Integer.parseInt(sc.nextLine());
System.out.println("Enter the Month as a Number from 1 to 12! ");
int month = Integer.parseInt(sc.nextLine()); // 0 ist Januar. 11 ist Dezember.
System.out.println("Enter the Year please! ");
int year = Integer.parseInt(sc.nextLine());
this.JndUniAt.set(year, month, date);
}
public Calendar joinedUniAt() {
return this.JndUniAt;
}
public void setField() {
System.out.println("Enter the Field Please");
Scanner sd = new Scanner(System.in);
this.Field = sd.nextLine();
}
public String getField() {
return this.Field;
}
public void addLVA(Course l) {
this.LectrueOfLecturer.add(l);
}
public void listLVA() {
try {
Enumeration e = this.LectrueOfLecturer.elements();
while (e.hasMoreElements()) {
System.out.println(e.nextElement());
}
}catch(NoSuchElementException no) {
System.out.println("Course List is empty..");
}
}
public void delLVA() {
this.listLVA();
if(this.LectrueOfLecturer.isEmpty()==false) {
Lecturer d = new Lecturer("","","");
Course le = new Course(0,"");
System.out.println("Enter the Code of the Course..");
le.setCode();
if(this.LectrueOfLecturer.contains(le)==true) {
this.LectrueOfLecturer.remove(le);
}else if(this.LectrueOfLecturer.contains(le)==false) {
System.out.println("The Lecturer is not part of this Course");
}
}else {
System.out.println("can not be deleted..");
}
}
public void delthisLVA(Course g ) {
if(this.LectrueOfLecturer.contains(g)==true) {
this.LectrueOfLecturer.remove(g);
}
}
}
يرجى مراسلتي ﻷي مشكلة أو سؤال.
المرجع: منهاج أساسيات البرمجة الموجهة، د.بورجو يلدز - الجامعة التركية الألمانية