أمثلة وتمارين محلولة في لغة جافا
08 Feb 2020
آخر تعديل: 20 Mar 2021
إليك تمارين وأمثلة في البرمجة الموجهة في لغة البرمجة جافا مع الحلول.
الأسئلة جميعها مترابطة مع بعضها لإتمام كتابة وظائف في نفس البرنامج.
الحلول المطروحة هي حلول ممكنة وليست حلولًا مثاليّة.
الأسئلة
السؤال الأول
يتطلب كتابة برنامج لإدارة الطلاب حيث يتم حفظ الطلاب والمواد الدراسية ويقوم الطلاب لاحقًا بتسجيل أو إلغاء تسجيل أنفسهم في المواد.
البرنامج الرئيسي يكون في الملف: Main.java (انظر الكود أدناه)
والمطلوب هو:
-
كتابة أصناف (class) للطالب والجامعة: Student.java و University.java
-
حفظ هذه الأصناف في نفس مجلد Main.java
-
كتابة الوظائف المطلوبة أدناه في مكان العبارة TODO
في النهاية يجب أن يكون البرنامج قادرًا على إنشاء طلاب وحفظهم وعرضهم.
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
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;
}
}
}
}
السؤال الرابع
قم بتطوير برنامجك السابق بحيث يشتمل على المهام التالية:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
الكود في هذا الصنف طويل بسبب احتوائه على حالات زائدة غير مطلوبة في السؤال مثل عرض خيار إضافة طالب في حال عدم العثور عليه وما إلى ذلك..
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
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
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);
}
}
}
يرجى مراسلتي ﻷي مشكلة أو سؤال.
المرجع: منهاج أساسيات البرمجة الموجهة، د.بورجو يلدز - الجامعة التركية الألمانية