package ex2.data; //import java.util.ArrayList; /** * Η κλάση Student παριστά ένα φοιτητή στο σύστημα του φοιτητολογίου. * Η κλάση κληρονομεί την κλάση {@link Person}. * Student's extra attributes: Student Id, Semester * @author Ioulia Anastasiou, Iraklis Lefas, Alexandros Feidis */ public class Student extends Person { private String StudId; private int Semester; //private Course[] Studies; //private ArrayList <Course> Studies; // constructor /** * @param SurName :person's surname * @param FirstName :person's first name * @param FatherName :person's father name * @param BirthYear :person's birth year * @param EMail :person's email addNewStrs * @param PhoneNo :person's phone number * @param StudId :student's unique identification number * @param Semester :student's semester */ public Student (String SurName, String FirstName, String FatherName, int BirthYear, String EMail, String PhoneNo, String StudId, String Semester) { super (SurName, FirstName, FatherName, BirthYear, EMail, PhoneNo); //inherited from class PERSON this.StudId = StudId; this.Semester = Semester; //Studies = new ArrayList (); } //getters&setters public String getStudId () { return StudId; } public void setStudId (String StudId) { this.StudId = StudId; } public int getSemester () { return Semester; } public void setSemester (int Semester) { this.Semester = Semester; } /** * shows all data for a student */ @Override public void ShowAll() { super.ShowAll(); System.out.println ("Professor's Id.........:" + ProfId); System.out.println ("Student's Id...........:" + StudId); System.out.println ("Student's Semester.....:" + Semester); } /** * returns all data in one string */ @Override public String toString () { String OneString; OneString = super.toString() + " / " + StudId + " / " + Semester; return OneString; } }package ex2.data; import java.util.ArrayList; /** * Η κλάση Professor παριστά έναν καθηγητή στο σύστημα του φοιτητολογίου. * Η κλάση κληρoνομεί την κλάση {@link Person}. * Proffesor's extra attributes: Teacher Id, Specialism * @author Ioulia Anastasiou, Iraklis Lefas, Alexandros Feidis */ public class Professor extends Person { private String ProfId; //private ArrayList <Course> Teaches; private String Specialism; // constructor /** * * @param SurName :person's surname * @param FirstName :person's first name * @param FatherName :person's father name * @param BirthYear :person's birth year * @param EMail :person's email addNewStrs * @param PhoneNo :person's phone number * @param ProfId :professor's unique identification number * @param Expertise :professor's science expertise * //@param Teaches :courses that the professor teaches */ public Professor (String SurName, String FirstName, String FatherName, int BirthYear, String EMail, String PhoneNo, String ProfId, String Specialism) { super (SurName, FirstName, FatherName, BirthYear, EMail, PhoneNo); //inherited from class PERSON this.ProfId = ProfId; this.Specialism = Specialism; //Teaches = new ArrayList (); } //getters&setters public String getProfId () { return ProfId; } public void setProfId (String ProfId) { this.ProfId = ProfId; } public String getSpecialism() { return Specialism; } public void setSpecialism (String Specialism) { this.Specialism = Specialism; } /*public ArrayList <Course> getTeaches () { return Teaches; //no need here, as the Teaches function is performed in Person class } */ /** * shows all data for a professor */ @Override public void ShowAll() { super.ShowAll(); System.out.println ("Professor's Id.........:" + ProfId); System.out.println ("Professor's Specialism :" + Specialism); } /** * returns all data in one string */ @Override public String toString () { String OneString; OneString = super.toString() + " / " + ProfId + " / " + Specialism; return OneString; } } package ex2.data; import java.util.Date; import java.util.ArrayList; /** * Η κλάση Person παριστά ένα άτομο. Περιέχει τα χαρακτηριστικά του * ενός ατόμου τα οποία ενδιαφέρουν την εφαρμογή του φοιτητολογίου και * τις αντίστοιχες λειτουργίες, δηλ. τα κοινά στοιχεία φοιτητών και καθηγητών, * τα οποία κληρονομούνται από τις αντίστοιχες κλάσεις. * @author Ioulia Anastasiou, Iraklis Lefas, Alexandros Feidis */ public class Person { protected String SurName; protected String FirstName; protected String FatherName; protected int BirthYear; protected String EMail; protected String PhoneNo; protected ArrayList <Course> Courses; //protected String IDNum; // private static int Counter = 0; /* public static void ShowCounter () { System.out.printf ("Μέχρι στιγμής έχουν δημιουργηθεί %d στιγμιότυπα της κλάσης Person\n", Counter); } */ // constructor /** * * @param SurName :person's surname * @param FirstName :person's first name * @param FatherName :person's father name * @param BirthYear :person's birth year * @param EMail :person's email addNewStrs * @param PhoneNo :person's phone number * @param Courses :person's list of affiliated courses */ public Person (String SurName, String FirstName, String FatherName, int BirthYear, String EMail, String TelNo) { this.SurName = SurName; this.FirstName = FirstName; this.FatherName = FatherName; this.BirthYear = BirthYear; this.EMail = EMail; this.PhoneNo = PhoneNo; Courses = new ArrayList(); // Counter++; } // constructor /** * * @param SN :person's surname * @param FN :person's first name * @param FaNam :person's father name */ /* public Person (String SN, String FN, String FaNam) { this (SN, FN, FaNam, 0, null); //SurName = SN; //FirstName = FN; //FatherName = FaNam; //Counter++; } /* /* public Person (Person C) { SurName = C.SurName; FirstName = C.FirstName; FatherName = C.FatherName; BirthYear = C.BirthYear; IDNum = C.IDNum; //Counter++; } */ // getters & setters for person's attributes public String getSurName () { return SurName; } public void setSurName (String SurName) { this.SurName = SurName; } public String getFirstName () { return FirstName; } public void setFirstName (String FirstName) { this.FirstName = FirstName; } public String getFatherName () { return FatherName; } public void setFatherName (String FatherName) { this.FatherName = FatherName; } public int getBirthYear () { return BirthYear; } public void setBirthYear (int BirthYear) { this.BirthYear = BirthYear; } public String getEMail () { return EMail; } public void setEMail (String EMail) { this.EMail = EMail; } public String getPhoneNo () { return PhoneNo; } public void setPhoneNo (String PhoneNo) { this.PhoneNo = PhoneNo; } public ArrayList<Course> getCourses () { return Courses; } public void setCourses(ArrayList<Course>Courses) { this.Courses =Courses; } /** * calculates peson's age to check validity of data */ public int CalcAge (int YY) { int Age; Age = YY - BirthYear; return Age; } /** * Adds a new course entry in person's list of courses * @param c : course to be added */ public void AddCourse(Course c) { Courses.add (c); //namh balw ki edw search gia hascourse? } /** * Deletes a couirse entry from person's list of courses. * The course is searched and if not found, no further action is performed. *@param CourseId : Id of the course to be deleted * ο κωδικός του μαθήματος που θα αφαιρεθεί από τη λίστα. */ public void DeleteCourse(String CourseId) { for(int i = 0;i < Courses.size (); i++) { if(Courses.get(i).getCourseId().equals (CourseId) || Courses.get(i).getCourseName().equalsIgnoreCase (CourseId)) //oxi equals coursename? Courses.remove (i); //ena check edw an thelei exception } } /** * Checks if person is affiliated with a course. * Search is performed by course's name or id (use of for:each loop) * The course is searched and if not found, no further action is performed. * @param CourseId Id of the course to be searched for * @param c : specific course object * @return true: course found / false: course not found. */ public boolean HasCourse(String CourseId) { for (Course c: Courses) { // mporuse na ginei kai opws h delets course (oxi xrhsh for:each) ? if(c.getCourseId().equals (CourseId) || c.getCourseName().equalsIgnoreCase (CourseID)) //oxi course name? return true; } return false; } /** * Returns a string of person's course names. * If no course has been assigned to person, prints a suitable message *@return NewStr: new string that shows the courses */ public String GetNamesOfCourses() { String NewStr=""; //alt+F3 to modify all selections in sublime text if (this.Courses==null) { NewStr ="No course has been assigned"; } else { for (int i=0; i<this.Courses.size(); i++) { Course tmp=this.Courses.get(i); NewStr+=tmp.getCourseName(); if(i<(this.Courses.size()-1)) NewStr+=","; } } return (NewStr); } /** * shows all data for a person */ public void ShowAll () { System.out.println (" PERSON DATA "); System.out.println ("========================"); System.out.println ("Surname................: " + SurName); System.out.println ("Name...................: " + FirstName); System.out.println ("Father's Name..........: " + FatherName); System.out.println ("Year of birth..........: " + BirthYear); System.out.println ("Email..................: " + EMail); System.out.println ("Phone Number...........: " + PhoneNo); } /** * returns all data in one string */ @Override public String toString () { String OneString; OneString = SurName + " / " + FirstName + " / " + FatherName + " / " + BirthYear + " / " + EMail " / " + PhoneNo; return OneString; } /** checks if bitrh year given is valid */ public static boolean ValidBirthYear (int ToBeChecked) { if (ToBeChecked > 1900 && ToBeChecked <= new Date ().getYear ()) return true; return false; } } import ex2.data.Course; import ex2.data.Person; import ex2.data.Professor; import ex2.data.Student; import ex2.data.Grade; import java.util.Scanner; public class StudentSystem { Lists MainList; Scanner input; public StudentSystem (){ MainList = new Lists(); FixedRecords(); input = new Scanner (System.in , "windows-1253"); //?????? } //START OF ΜΑΙΝ public static void main(String[] args){ System.out.println("---------------------"); System.out.println(" STUDENT APPLICATION "); StudentSystem Final= new StudentSystem(); Final.Menu(); } public void Menu () { int menu; do { System.out.println ("==========================================="); System.out.println (" MAIN MENU "); System.out.println ("==========================================="); System.out.println ("1. Show Professors"); System.out.println ("2. Show Students"); System.out.println ("3. Show Courses"); System.out.println ("4. Show Grades"); System.out.println ("5. Add New Person"); System.out.println ("6. Edit Person"); System.out.println ("7. Delete Person"); System.out.println ("8. Add New Course"); System.out.println ("9. Edit Course"); System.out.println ("10. Delete Course"); System.out.println ("11. Assign Course to a Person"); System.out.println ("12. Delete Course from a Person"); System.out.println ("13. Insert grade to a Student"); System.out.println ("14. Show Statistic Information"); System.out.println ("15. Save/Load Data"); System.out.println ("0. Exit"); System.out.println ("==========================================="); System.out.println("Type your choice please:"); System.out.println(""); do { while (!input.hasNextInt()) { System.out.println ("Wrong input! Choice must be integer number from 0 to 15"); input.next(); } menu=input.nextInt(); } while(menu<0); System.out.println(""); switch (menu) { case 1: ShowProfessors (); Pause(); break; case 2: ShowStudents (); Pause(); break; case 3: ShowCourses (); Pause(); break; case 4: ShowGrades(); Pause(); break; case 5: AddPerson (); Pause(); break; case 6: ManipulatePerson (); Pause(); break; case 7: DeletePerson (); Pause(); break; case 8: AddNewCourse (); Pause(); break; case 9: ManipulateCourse (); Pause(); break; case 10:DeleteCourse (); Pause(); break; case 11:AddCourseToPerson (); Pause(); break; case 12:DeleteCourseFromPerson (); Pause(); break; case 13:AddGrade(); Pause(); break; case 14:AvgAllStudents();AvgAllCourses(); Pause(); break; case 15:LoadSaveDialogue(); Pause(); break; case 0: break; default: System.out.println("No such choice exists!!!"); Pause(); System.out.println(""); break; } } while (menu != 0); System.out.println ("Exiting...Goodbye!!"); System.out.println(""); } //Start of data insertion /** * adds fixed entries to the application */ public void FixedRecords () { Course c; c=new Course("001","PLIROFORIKH",3); MainList.AddCourse(c); c=new Course("002","DIKTYA ASFALEIA",1); MainList.AddCourse(c); c=new Course("003","VASEIS DEDOMEWN",2); MainList.AddCourse(c); Student s; s=new Student("F0001","ANTONIOU","Antonios","[email protected]","699999999",3); MainList.AddPerson(s); s.AddCourse(MainList.GetCourseByID("001")); s.AddCourse(MainList.GetCourseByID("003")); s=new Student("F0002","GEORGIOU","Georgios","[email protected]","6988888888",1); MainList.AddPerson(s); s.AddCourse(MainList.GetCourseByID("002")); s=new Student("F0003","DIMITRIOU","Dimitrios","[email protected]","6977777777",2); MainList.AddPerson(s); s.AddCourse(MainList.GetCourseByID("003")); try { Grade g1= new Grade("F0001","001",5.2); MainList.AddGrade(g1); } catch (Exception e) { System.out.println(e.getMessage()); } try { Grade g2= new Grade("F0001","003",3.2); MainList.AddGrade(g2); } catch (Exception e) { System.out.println(e.getMessage()); } try { Grade g3= new Grade("F0002","002",6.2); MainList.AddGrade(g3); } catch (Exception e) { System.out.println(e.getMessage()); } try { Grade g4= new Grade("F0003","003",4.2); MainList.AddGrade(g4); } catch (Exception e) { System.out.println(e.getMessage()); } Professor p; p=new Professor("K005","IOANNOU","Ioannis","[email protected]","65555555555","Pliroforiki"); MainList.AddPerson(p); p.AddCourse(MainList.GetCourseByID("001")); p.AddCourse(MainList.GetCourseByID("003")); p=new Professor("K008","KONSTANTINOU","Konstantinos","[email protected]","63333333333","Diktya"); MainList.AddPerson(p); p.AddCourse(MainList.GetCourseByID("002")); p=new Professor("K010","VASILEIOU","Vasileios","[email protected]","622222222","Vaseis Dedomenwn"); MainList.AddPerson(p); p.AddCourse(MainList.GetCourseByID("003")); } /** * shows the list of professors * returns the list of professors of @Person class, along with the courses they teach (@GetCourseByID) */ public void ShowProfessors() { int i=1; System.out.println ("LIST OF PROFESSORS"); System.out.println ("=================="); System.out.println ("Number Professor_ID Surname Name Email PhoneNo_Number Specialization Course"); System.out.println ("**********************************************************************"); for (Person tmp: MainList.getP_List ()) if(tmp instanceof Professor) System.out.printf("%2d %-10s %-20s %-20s %-20s %-12s %-20s Didaskei: %s\n",i++,((Professor)tmp ).getProfId(),tmp.getSurName(),tmp.getFirstName (),tmp.getEmail(),tmp.getPhoneNo (),((Professor) tmp).getSpecialism(), tmp.GetCoursesNames()); } /** * shows the list of Students * returns the list of students of @Person class, along with the courses they attend (@GetCourseByID) */ public void ShowStudents() { int i=1; System.out.println ("LISTOF STUDENTS"); System.out.println ("================"); System.out.println ("Number Student_ID Surname Name Email PhoneNo_Number Semester Courses"); System.out.println ("******************************************************************"); for (Person tmp:MainList.getP_List()) if(tmp instanceof Student) System.out.printf("%2d %-10s %-20s %-20s %-20s %-12s %-10d Parakolouthei: %s\n",i++,((Student)tmp).getStudId(),tmp.getSurName(),tmp.getFirstName (),tmp.getEmail(),tmp.getPhoneNo(),((Student) tmp).getSemester(),tmp.getCourses()); } /** * shows the list of courses * returns the list of courses of @Course class, along with their info */ public void ShowCourses() { int i=1; System.out.println ("LIST OF COURSES"); System.out.println ("==============="); System.out.println ("Number Course_ID Course_Title Semester"); System.out.println ("**************************************"); for (Course tmp:MainList.getC_List()) System.out.printf("%2d %-10s %-25s %d\n",i++,tmp.getCourseID(),tmp.getCourseName(),tmp.getCourseSemester()); } /** * shows the list of grades * returns the list of grades of @Grade class, along with ttheir info */ public void ShowGrades() { int i=1; System.out.println ("LIST OF GRADES"); System.out.println ("=============="); System.out.println ("Number Course Student Grade"); System.out.println ("***************************"); for (Grade tmp:MainList.getGrades()) System.out.printf("%2d %5s %10s %15f\n",i++,tmp.Grade_Course_Id(),tmp.getGrade_Student_Id(),tmp.getGrade()); } /** * adds a new person to the list of persons (choice between student or professor) * checks: choice number validity, if prof. exists */ public void AddPerson() { int option; System.out.println ("Press 1 to add a new professor"); System.out.println ("Press 2 to add a new student"); System.out.printf ( "Type your choice: "); do{ while (!input.hasNextInt()) { System.out.println ("Wrong input! Please choose a number!"); input.next(); } option= input.nextInt(); } while(option <=0); input.nextLine(); //clears the input buffer if (option==1){ Professor p; System.out.println ("Type professor's ID:"); String tmpProfId= input.nextLine(); if(MainList.CheckProf(tmpProfId)) { System.out.println("Professor allready exists"); return; } System.out.printf ("Type professor's surname:"); String tmpSurName= input.nextLine(); System.out.printf ("Type professor's first name:"); String tmpFirstName= input.nextLine(); System.out.printf ("Type professor's email:"); String tmpEmail= input.nextLine(); System.out.printf ("Type professor's Phone number:"); String tmpPhoneNo= input.nextLine(); System.out.printf ("Type professor's Specialization:"); String tmpSpecialism= input.nextLine(); p= new Professor(tmpProfId,tmpSurName,tmpFirstName,tmpEmail,tmpPhoneNo,tmpSpecialism); MainList.AddPerson(p); System.out.println("Professor inserted!"); } else if(option==2) { Student s; System.out.printf("Type student's ID number:"); String tmpStudId= input.nextLine(); if(MainList.CheckStudent(tmpStudId)) { System.out.println("student allready exists!"); return; } System.out.printf("Type student's surname: "); String tmpSurName=input.nextLine(); System.out.printf("Type student's first name: "); String tmpFirstName=input.nextLine(); System.out.printf("Type student's Email: "); String tmpEmail=input.nextLine(); System.out.printf("Type student's PhoneNo number: "); String tmpPhoneNo=input.nextLine(); System.out.printf("Type student's Semester: "); int tmpSemester; do{ while (!input.hasNextInt()) { System.out.println ("Wrong input! Please choose a valid number!"); input.next(); } tmpSemester= input.nextInt(); }while (tmpSemester<= 0); s=new Student(tmpStudId, tmpSurName, tmpFirstName, tmpEmail, tmpPhoneNo, tmpSemester); MainList.AddPerson(s); System.out.println ("Student sucessfully inserted! "); } else{ System.out.println ("NO SUCH CHOICE EXISTS"); } } /** * edits a person's data in the list of persons and prints the edited entry afterwards. * checks: semester number validity, if person not exists, confirm the edit */ public void ManipulatePerson() { char option; input.nextLine();// clear the input buffer System.out.printf ("Type person's to be edited data:\n "); System.out.printf ("Type surname: "); String tmpSurName = input.nextLine(); System.out.printf ("Type name: "); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson (tmpSurName, tmpFirstName); if(!MainList.CheckPerson(tmpP)) { return; } System.out.println(""); System.out.printf ("\"confirm the edit:\n"+ tmpP + " \nY/N?: "); do{ option = input.next().charAt (0); input.nextLine();// clear the input buffer if(option=='N' || option=='n' || option=='N' || option=='v') break; else if (option=='Y' || option!='y' || option=='Y' || option!='υ') { System.out.printf("type new surname: "); String newSurName=input.nextLine(); tmpP.setSurName(newSurName); System.out.printf("type new name: "); String newFirstName=input.nextLine(); tmpP.setFirstName(newFirstName); // na balw kai father name: FatherName System.out.printf("type new Email: "); String newEmail=input.nextLine(); tmpP.setEmail(newEmail); System.out.printf("type new Phone number: "); String newPhoneNo=input.nextLine(); tmpP.setPhoneNo(newPhoneNo); if(tmpP instanceof Student){ System.out.printf("type new student ID: "); String newStudId = input.nextLine(); ((Student) tmpP).setAM(newStudId); System.out.printf("type new Semester: "); int newSemester; do { while (!input.hasNextInt()){ System.out.println("Wrong input! Please choose a number!"); input.next(); } newSemester = input.nextInt(); }while (newSemester <= 0); ((Student) tmpP).setSemester(newSemester); } else if (tmpP instanceof Professor) { System.out.printf("Type new professor's ID: "); String newProfId = input.nextLine(); ((Professor) tmpP).setProfId(newProfId); System.out.printf("Type new professor's Specialization: "); String newSpecialism = input.nextLine(); ((Professor) tmpP).setSpecialism(newSpecialism); } } System.out.println(""); System.out.println ("New entry:\n "+ tmpP); }while(option=='N' || option=='n' || option=='N' || option=='v'); } /** * deletes a person from the list of persons * checks: if person exists, confirm the deletion */ public void DeletePerson(){ char option; input.nextLine();//clean input buffer System.out.printf("Type person's data to be deleted:\n "); System.out.printf("type surname:"); String tmpSurName = input.nextLine(); System.out.printf("type first name:"); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson(tmpSurName, tmpFirstName); if(!MainList.CheckPerson(tmpP)){ return; } System.out.println(""); System.out.printf("confirm the deletion: :\n "+ tmpP + " \nY/N?: "); do{ option=input.next().charAt(0); if(option=='N' || option=='n' || option=='N' || option=='v') break; else if (option=='Y' || option!='y' || option=='Y' || option!='υ') MainList.DelPerson(tmpP); System.out.println("person sucessfully deleted"); }while(option=='N' || option=='n' || option=='N' || option=='v'); } /** * adds a new course in the list of courses * checks: semester number validity, if course exists */ public void AddNewCourse(){ input.nextLine();//clear input buffer Course c; System.out.printf("type course ID or course name: "); String tmpCourseID = input.nextLine(); if(MainList.CheckCourse(tmpCourseID)){ System.out.println("course already exists!"); return; } System.out.printf("type course name: "); String tmpCourseName = input.nextLine(); System.out.printf("type course Semester: "); int tmpCourseSemester; do { while (!input.hasNextInt()) { System.out.println("Wrong input. Please type a valid semester number!"); input.next(); } tmpCourseSemester = input.nextInt(); }while (tmpCourseSemester <= 0); c= new Course(tmpCourseID, tmpCourseName, tmpCourseSemester); MainList.AddCourse(c); System.out.println("course sucessfully inserted"); } /** * modifies a course's data in the list of courses * checks: semester number validity, if course exists, confirm modification */ public void ManipulateCourse() { input.nextLine();//clear input buffer char option; System.out.printf("type course ID or course name: "); String tmpCourseID = input.nextLine(); Course tmpC = MainList.GetCourseByID(tmpCourseID); if(!MainList.CheckCourse(tmpCourseID)){ System.out.println("no such course exists!"); return; } System.out.println(""); System.out.printf ("confirm course modification:\n"+ tmpC + " \nY/N?: "); do{ option=input.next().charAt(0); if(option=='N' || option=='n' || option=='N' || option=='v') break; else if (option=='Y' || option!='y' || option=='Y' || option!='υ') { input.nextLine();//clear input buffer System.out.printf("type course name: "); String tmpCourseName = input.nextLine(); tmpC.setCourseName(tmpCourseName); System.out.printf("type course Semester: "); int tmpCourseSemester; do { while (!input.hasNextInt()) { System.out.println("Wrong input. Please type a valid semester number!"); input.next(); } tmpCourseSemester = input.nextInt(); }while (tmpCourseSemester <= 0); tmpC.setCourseSemester(tmpCourseSemester); } System.out.println(""); System.out.printf ("course has been modified :\n"+ tmpC); }while(option=='N' || option=='n' || option=='N' || option=='v'); } /** * deletes a course from the list of courses * checks: if course exists, confirm deletion */ public void DeleteCourse() { input.nextLine();//clear input buffer char option; System.out.printf("type course ID of course name: to be deleted: "); String tmpCourseID = input.nextLine(); Course tmpC = MainList.GetCourseByID(tmpCourseID); if(!MainList.CheckCourse(tmpCourseID)){ System.out.println("no such course exists!"); return; } System.out.println(""); System.out.printf("confirm course deletion:\n "+ tmpC + " \nY/N?: "); do{ option=input.next().charAt(0); if(option=='N' || option=='n' || option=='N' || option=='v') break; else if (option=='Y' || option!='y' || option=='Y' || option!='υ') MainList.DelCourse(tmpC); System.out.println("course sucessfully deleted"); }while(option=='N' || option=='n' || option=='N' || option=='v'); } /** * assigns a course from the list of courses to persons * checks: if person exists, if course has already been assigned */ public void AddCourseToPerson() { input.nextLine();//clear input buffer System.out.printf("type person's data to be assigned to a course:\n "); System.out.printf("type surname:"); String tmpSurName = input.nextLine(); System.out.printf("type name:"); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson(tmpSurName, tmpFirstName); if(!MainList.CheckPerson(tmpP)){ return; } System.out.println(""); System.out.printf("the person is:\n "+ tmpP); System.out.println(""); System.out.printf("type Course ID or Course Title: "); String tmpCourseID = input.nextLine(); Course tmpC = MainList.GetCourseByID(tmpCourseID); if(tmpP.HasCourse(tmpC.getCourseID())) System.out.println("course already exists!"); else{ tmpP.AddCourse(tmpC); System.out.println(""); System.out.println("course sucessfully assigned"); } } /** * deletes a course from a person * prints a list of assigned courses, choice by course id or course name * checks: if person exists, if course has already been assigned, confirm deletion */ public void DeleteCourseFromPerson() { char option; input.nextLine();//clear input buffer System.out.printf("type person's data for course deletions:\n "); System.out.printf("type surname:"); String tmpSurName = input.nextLine(); System.out.printf("type name:"); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson(tmpSurName, tmpFirstName); if(!MainList.CheckPerson(tmpP)){ return; } System.out.println(""); System.out.printf("person's data :\n "+ tmpP); System.out.println(""); System.out.printf("courses assigned to person :\n "+ tmpP.getCourses()); System.out.println(""); System.out.printf("type course ID or course name: "); String tmpCourseID = input.nextLine(); if(!tmpP.HasCourse(tmpCourseID)) System.out.println("course does not exist!"); else{ System.out.println(""); System.out.printf("\"confirm course deletion :\n "+ MainList.GetCourseByID(tmpCourseID) + " \nY/N?: "); option=input.next().charAt(0); if(option=='N' || option=='n' || option=='N' || option=='v') return; else if (option=='Y' || option!='y' || option=='Y' || option!='υ') { tmpP.RemoveCourse(tmpCourseID); System.out.println(""); System.out.println("course sucessfully deleted!"); } } } /** * adds grade to an assigned course to a student * prints a list of assigned courses, choice by course id * checks: valid grade, if course assigned, if course already graded, grade number type validity */ public void AddGrade() { input.nextLine();//clear input buffer char option; System.out.printf("type person's data for grading:\n "); System.out.printf("type surname:"); String tmpSurName = input.nextLine(); System.out.printf("type name:"); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson(tmpSurName, tmpFirstName); if(!MainList.CheckPerson(tmpP)){ return; } if (tmpP instanceof Student) { Student tmpS = (Student)tmpP; System.out.println("courses registerd into:\n "+ tmpP + " \neinai: "); System.out.println(tmpP.getCourses()); Grade g; boolean check=false; double tmpGrade; do{ String tmpGrade_Student_Id = tmpS.getAM(); System.out.printf("type course ID or course name:"); String tmpGrade_Course_Id = input.nextLine(); if(tmpS.HasCourse(tmpGrade_Course_Id)) { if(MainList.CheckGrade(tmpGrade_Course_Id)) { g=MainList.FindGrade(tmpGrade_Course_Id); System.out.println("grading already exists" + MainList.GetCourseByID(tmpGrade_Course_Id)); System.out.println("grade:" + MainList.FindGrade(tmpGrade_Course_Id)); System.out.printf("confirm grade modification Y/N:"); option=input.next().charAt(0); if(option=='N' || option=='n' || option=='N' || option=='v') return; else if (option=='Y' || option!='y' || option=='Y' || option!='υ'){ System.out.printf("type course grade:"); do { /*while(!input.hasNextDouble()) { System.out.println("wrong input! please type valid number type "); System.out.printf("Dwste apodekti vathmologia : "); input.next(); } */ tmpGrade = input.nextDouble(); }while (tmpGrade <= 0); g.setGrade(tmpGrade); System.out.println("grade sucessfully modified: " + g); return; } } else{ System.out.printf("type course grade: "); do { /*while( !input.hasNextDouble()) { System.out.println("Aytos den einai swstos vathmos!"); System.out.printf("Dwste apodekti vathmologia: "); input.next (); } */ tmpGrade = input.nextDouble(); }while (tmpGrade <= 0 ); try{ g= new Grade(tmpGrade_Student_Id, tmpGrade_Course_Id, tmpGrade); check=true; MainList.AddGrade(g); System.out.println("grade sucessfully inserted :" + g); } catch (Exception e) { System.out.println (e.getMessage()); } } } else System.out.println("this course has not been assigned to the student! "); }while (!check); } else System.out.println("no such student exists"); } /** * calculates the average grade of a student * checks: if student exists * not used */ public void AvgofStudent (){ System.out.println("tpye student's data to be searched:\n"); System.out.println("type surname: "); String tmpSurName = input.nextLine(); System.out.println("type name: "); String tmpFirstName = input.nextLine(); Person tmpP = MainList.FindPerson (tmpSurName, tmpFirstName); if (!MainList.CheckPerson(tmpP)){ return; } if (tmpP instanceof Student){ Student tmpS= (Student)tmpP; System.out.println("the average of student:" + tmpS + "\nis: " + (MainList.AVG_Student(tmpS.getStudId()))); } else System.out.println("no such student exists!"); } /** * calculates the average of all students * checks: if students list is empty */ public void AvgAllStudents(){ if (MainList.getP_List().isEmpty()) System.out.println("student list is empty!"); else { System.out.println("average per student: "); System.out.println("********************"); System.out.println("student_ID surname name average"); for (Person S: MainList.getP_List()){ if (S instanceof Student){ Student tmpS = (Student) S; System.out.printf("%-6s %-15s %-15s %f\n", tmpS.getStudId(), tmpS.getSurName(), tmpS.getFirstName (), MainList.AVG_Student(tmpS.getStudId())); } } } System.out.println(""); } /** * average of all courses (per course) * checks: if list of courses is empty */ public void AvgAllCourses(){ if(MainList.getC_List().isEmpty()) System.out.println("list of courses is empty!"); else{ System.out.println("average per course:"); System.out.println("******************"); int i=1; System.out.println("course average Μ/Ο"); for (Course C: MainList.getC_List()){ System.out.printf("%d %-25s %f\n" , i++, C.getCourseName(), MainList.AVG_Course(C.getCourseID())); } } System.out.println(""); } /** * saves persons' data * lists are saved in desktop * checks: for read/save of files */ public void SaveData(){ String FnC; boolean Rc; System.out.println(""); System.out.println("Save course Data"); System.out.println("name of file to be saved: "); FnC = input.nextLine(); Rc = MainList.SaveCourses (FnC); if (Rc) System.out.println("save completed..."); else System.out.println("save failed..."); String FnP; boolean Rp; System.out.println (""); System.out.println("save professor data"); System.out.print ("name of file to be saved: "); FnP = input.nextLine(); Rp = MainList.SaveProfessors (FnP); if (Rp) System.out.println("save completed..."); else System.out.println("save failed..."); String FnS; boolean Rs; System.out.println (""); System.out.println("save student data"); System.out.print ("name of file to be saved: "); FnS = input.nextLine(); Rs = MainList.SaveStudents (FnS); if (Rs) System.out.println("save completed.."); else System.out.println("save failed..."); String FnG; boolean Rg; System.out.println (""); System.out.println("save grade data"); System.out.print ("name of file to be saved:"); FnG = input.nextLine(); Rg = MainList.SaveGrades (FnG); if (Rg) System.out.println("save completed.."); else System.out.println("save failed..."); } /** * loads data of students & professors form desktop * 4 files must be loaded * checks: read/save file */ public void LoadData (){ String FnC; boolean Rc; System.out.println(""); System.out.println("course data loading"); System.out.println("name of file to be loaded:"); FnC = input.nextLine(); Rc = MainList.LoadCourses (FnC); if (Rc) System.out.println("loading completed..."); else System.out.println("loading not completed..."); String FnP; boolean Rp; System.out.println(""); System.out.println("professors' data loading"); System.out.println("name of file to be loaded:: "); FnP = input.nextLine(); Rp = MainList.LoadProfessors (FnP); if (Rp) System.out.println("loading completed..."); else System.out.println("loading not completed..."); String FnS; boolean Rs; System.out.println (""); System.out.println("students's data loading"); System.out.print ("name of file to be loaded: "); FnS = input.nextLine(); Rs = MainList.LoadStudents (FnS); if (Rs) System.out.println("loading completed..."); else System.out.println("loading not completed..."); String FnG; boolean Rg; System.out.println (""); System.out.println("grade data loading"); System.out.print ("Όname of file to be loaded: "); FnG = input.nextLine(); Rg = MainList.LoadGrades (FnG); if (Rg) System.out.println("loading completed..."); else System.out.println("loading not completed..."); } /** * menu to choose between saving or loading data from application * checks: valid menu choice (number) */ Μενού επιλογήσς αποθήκευσης ή φόρτωσης των δεδομένων της εφαρμογής public void LoadSaveDialogue() { int option; char choice; System.out.println("Tyep 1 to save into a file") ; System.out.println("Type 2 to load from a file"); System.out.printf("Choice: "); do { while(!input.hasNextInt()) { System.out.println ("Wrong input! Please type a valid semester number"); input.next(); } option = input.nextInt(); }while (option <= 0 ); input.nextLine(); // clear input buffer if (option==1) { SaveData(); } else if (option ==2) { LoadData(); } else System.out.println("wrong choice!."); } /** * pauses program running, until <ENTER> input */ public void Pause () { Scanner K = new Scanner(System.in); System.out.println(""); System.out.printf("Press ENTER to continue..."); K.nextLine (); System.out.println (""); } }package ex2.ui; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; /*import ex2.data.Course; import ex2.data.Person; import ex2.data.Professor; import ex2.data.Student; import ex2.data.Grade; */ /** * Represents lists of professors, students, grades and courses */ public class Lists { ArrayList <Person> PersonList; ArrayList <Course> CourseList; ArrayList <Grade> GradeList; final String SaveDir = "ΤΟ ΔΙΚΌ ΣΑΣ PATH"; //bale to path edw public Lists() { PersonList = new ArrayList(); CourseList = new ArrayList(); GradeList = new ArrayList(); } //Getters public ArrayList <Person> getPersonList () { return PersonList; t public ArrayList<Course> getCourseList () { return CourseList; } public ArrayList <Grade> getGradeList () { return GradeList; } /** * adds a new person to the list of persons * @param p person to be added */ public void AddPerson (Person p) { PersonList.add (p); } /** * adds a new course to the list of courses * @param c course to be added */ public void AddCourse (Course c) { CourseList.add (c); } /** * adds a new grade to the list of grades * @param c course to be added */ public void AddGrade (Grade g) { GradeList.add (g); } /** * deletes a person from the list of persons * @param p person to be searched for */ public void DelPerson (Person p) { PersonList.remove (p); } /** * deletes a course from the list of courses * @param c course to be searched for */ public void DelCourse (Course c) { CourseList.remove (c); } /** * Checks if a course exists in the list of courses * Μέθοδος ελέγχου ύπαρξης μαθήματος στη λίστα των μαθημάτων. * @param CourseId course's ID number * @param CourseName course's name * @return true if course exists, false if not */ public boolean CheckCourse (String CourseId) { for (Course tmp : CourseList) { if (tmp.getCourseId(). equals(CourseId) || tmp.getCourseName(). equals(CourseId)) return true; } return false; } /** * checks if a person exists in the list of persons * @param p person to be searched for * @return true if person exists, false if not */ public boolean CheckPerson (Person p) { for (Person tmp: PersonList) { if (tmp == p) return true; } return false; } /** * checks if a professor exists in the list of persons * @param ProffesorId professor's ID to be searched for * @return true if professor exists, false if not */ public boolean CheckProfessor (String ProffesorId) { for (Person tmp: PersonList) { if (tmp instanceof Professor && ((Professor) tmp).getProffesorId().equals (ProffesorId)) return true; } return false; } /** * Checks if a student exists in the list of persons * @param StudentId student's ID number * @return true if student exists, false if not */ public boolean CheckStudent (String StudentId) { for (Person tmp: PersonList) { if (tmp instanceof Student && ((Student) tmp).getStudentId().equals (StudentId)) return true; } return false; } /** * Checks if a grade exists * @param CourseId course's id number * @return true if grade exists, false if not */ public boolean CheckGrade (String CourseId) { for (Grade tmp: GradeList) { if (tmp.getGrade_Course_Id() . equals (CourseId)) return true; } return false; } /** * searches for a person in the list of persons * @param SurName person's surname * @param FirstName person's first name * @return true if person exists, null if not */ public Person FindPerson (String SurName, String FirstName) { for (Person tmp: PersonList) { if (tmp.getSurName().equals (SurName) && tmp.getFirstName().equals (FirstName)) return tmp; } System.out.println("No such person exists!"); return null; } /** * searches for a grade in the list of grades * @param CourseId course's id * @return tmp if grade exists, null if not */ public Grade FindGrade (String CourseId) { for (Grade tmp: GradeList) { if (tmp.getGrade_Course_Id().equals(CourseId)) return tmp; } System.out.println("No such grade exists!"); return null; } /** * Searches for a course in the list of courses * @param CourseId course's ID number * @param CourseName course's name * @return tmp if course found, null if not */ public Course FindCourseById (String CourseId) { for (Course tmp: CourseList) { if (tmp.getCourseId().equals (CourseId) || tmp.getCourseName ().equals(CourseId)) return tmp; } return null; } /** * calculates the average of a student's grades * @param StudentId student's ID number * @return avg the average of a student's grades */ public double AVG_Student (String StudentId) { int i=0; double sum=0; double avg; for (Grade tmp: GradeList) { if (tmp.getGrade_Student_Id ().equals (StudentId)) { i++; sum+=tmp.getGrade (); } } avg=sum/i; return avg; } /** * calculates the average of a course's grades * @param CourseId course's ID number * @return avg course's average */ public double AVG_Course (String CourseId) { int i=0; double sum=0; double avg; for (Grade tmp: GradeList) { if (tmp.getGrade_Course_Id().equals(CourseId)) { i++; sum+=tmp.getGrade(); } } avg=sum/i; return avg; } /** * stores the list of professors in a file * @param FN name with which the file is gonna be saved * @return true if saved successfully, false if not */ public boolean SaveProfessorsList (String FN) { try { PrintWriter PF = new PrintWriter (SaveDir + FN + ".csv"); for (Person tmp: PersonList) { if (tmp instanceof Professor) { Professor P = (Professor) tmp; StringBuilder SB = new StringBuilder (); SB.append (P.getProffesorId()) .append (';') .append (P.SurName) .append (';') .append (P.FirstName) .append (';') .append (P.Email) .append (';') .append (P.Phone) .append (';') .append (P.getExpertise()) .append (';') .append (P.GetCoursesNames()); String Tbr = SB.toString(); PF.println (Tbr); } } PF.close(); } catch (FileNotFoundException e) { System.out.println ("ACHTUNG:" + e.getMessage () + "!!!"); return false; } return true; } /** * stores the list of students in a file * Μέθοδος αποθήκευσης της λίστας των φοιτητών σε αρχείο. * @param FN name with which the file is gonna be saved * @return true if saved successfully, false if not */ public boolean SaveStudentsList (String FN) { try { PrintWriter St = new PrintWriter (SaveDir + FN + ".csv"); for (Person tmp: PersonList) { if (tmp instanceof Student) { Student S = (Student) tmp; StringBuilder SB = new StringBuilder (); SB.append (S.getAM()) .append (';') .append (S.SurName) .append (';') .append (S.FirstName) .append (';') .append (S.Email) .append (';') .append (S.Phone) .append (';') .append (S.getSemester()) .append (';') .append (S.GetCoursesNames()); String Tbr = SB.toString(); St.println (Tbr); } } St.close (); } catch (FileNotFoundException e) { System.out.println ("ACHTUNG:" + e.getMessage () + "!!!"); return false; } return true; } /** * stores the list of courses in a file * @param FN name with which the file is gonna be saved * @return true if saved successfully, false if not */ public boolean SaveCoursesList (String FN) { try { PrintWriter Cr = new PrintWriter (SaveDir + FN + ".csv"); for (Course tmp: CourseList) { StringBuilder SB = new StringBuilder (); SB.append (tmp.getCourseId()) .append (';') .append (tmp.getCourseName()) .append (';') .append (tmp.getCourseSemester()); String Tbr = SB.toString(); Cr.println (Tbr); } Cr.close (); } catch (FileNotFoundException e) { System.out.println ("ACHTUNG:" + e.getMessage () + "!!!"); return false; } return true; } /** * stores the list of grades in a file * @param FN name with which the file is gonna be saved * @return true if saved successfully, false if not */ public boolean SaveGradesList (String FN) { try { PrintWriter Gr = new PrintWriter (SaveDir + FN + ".csv"); for (Grade tmp: GradeList) { StringBuilder SB = new StringBuilder (); SB.append (tmp.getGrade_Student_Id()) .append (';') .append (tmp.getGrade_Course_Id()) .append (';') .append (tmp.getGrade()); String Tbr = SB.toString(); Gr.println (Tbr); } Gr.close (); } catch (FileNotFoundException e) { System.out.println ("ACHTUNG:" + e.getMessage () + "!!!"); return false; } return true; } /** * loads the professors' list from a file * @param FN name of the file to be accessed * @return true if loaded successfully, false if not */ public boolean LoadProfessorsList (String FN) { boolean cool = false; //erase the pre-loaded entries ArrayList <Person> TmpList = new ArrayList (); for (Person tmp: PersonList) { if (tmp instanceof Professor) TmpList.add (tmp); } PersonList.removeAll (TmpList); TmpLitt = null; //end try { FileInputStream fs = new FileInputStream (SaveDir + FN + ".csv"); BufferedReader br = new BufferedReader (new InputStreamReader (fs)); String StrLine; while ((StrLine = br.readLine()) != null) { String[] Parts = StrLine.split (";"); Professor Pr = new Professor (Parts [0], Parts [1], Parts [2], Parts [3], Parts [4], Parts [5]); PersonList.add(Pr);t if (Parts.length>6) { ArrayList <Course> tmpCList = new ArrayList (); String [] tmpCourse = Parts[6].split (","); for (int i=0; i<tmpCourse.length; i++) { Course tmpC= new Course (null); tmpC.setCourseName (tmpCourse [i]); for (int j=0; j<CourseList.size(); j++) { if(tmpC.getCourseName().equals(CourseList.get(j).getCourseName())) tmpCList.add(CourseList.get(j)); } } Pr.setCourses (tmpCList); } else Pr.setCourses (null); } fs.close(); cool = true; } catch (FileNotFoundException e) { System.out.println ("Cannot access file" + SaveDir + FN); } catch (IOException e) { e.printStackTrace (); //prints the exceptions with additional info (class-line of error etc.) } return cool; } /** * loads the students' list from a file * @param FN name of the file to be accessed * @return true if loaded successfully, false if not */ public boolean LoadStudentsList (String FN) { boolean cool = false; //erase the pre-loaded entries ArrayList <Person> TmpList = new ArrayList (); for (Person tmp: PersonList) {if (tmp instanceof Student) TmpList.add (tmp); } PersonList.removeAll (TmpList); TmpLitt = null; //end try { FileInputStream fs = new FileInputStream (SaveDir + FN + ".csv"); BufferedReader br = new BufferedReader (new InputStreamReader (fs)); String StrLine; while ((StrLine = br.readLine()) != null) { String[] Parts = StrLine.split (";"); Student St = new Student (Parts [0], Parts [1], Parts [2], Parts [3], Parts [4], Integer.parseInt(Parts [5])); PersonList.add(St);t if (Parts.length>6) { ArrayList <Course> tmpCList = new ArrayList (); String [] tmpCourse = Parts[6].split (","); for (int i=0; i<tmpCourse.length; i++) { Course tmpC= new Course (null); tmpC.setCourseName (tmpCourse [i]); for (int j=0; j<CourseList.size(); j++) { if(tmpC.getCourseName().equals(CourseList.get(j).getCourseName())) tmpCList.add(CourseList.get(j)); } } St.setCourses (tmpCList); } else St.setCourses (null); } fs.close(); cool = true; } catch (FileNotFoundException e) { System.out.println ("Cannot access file" + SaveDir + FN); } catch (IOException e) { e.printStackTrace (); //prints the exceptions with additional info (class-line of error etc.) } return cool; } /** * loads the courses' list from a file * @param FN name of the file to be accessed * @return true if loaded successfully, false if not */ public boolean LoadCoursesList (String FN) { boolean cool = false; //erase the pre-loaded entries ArrayList <Course> TmpList = new ArrayList (); for (Course tmp: CourseList) { TmpList.add (tmp); } CourseList.removeAll (TmpList); TmpList = null; //end try { FileInputStream fs = new FileInputStream (SaveDir + FN + ".csv"); BufferedReader br = new BufferedReader (new InputStreamReader (fs)); String StrLine; while ((StrLine = br.readLine()) != null) { String [] Parts = StrLine.split (";"); Course Co = new Course (Parts [0], Parts [1], Integer.parseInt(Parts [2])); CourseList.add(Co); } fs.close(); cool = true; } catch (FileNotFoundException e) { System.out.println ("Cannot access file" + SaveDir + FN); } catch (IOException e) { e.printStackTrace (); //Τυπώνει τα exceptions μαζί με πληροφορίες όπως η γραμμή και η κλασή στην οποία } return cool; } /** * loads the grades' list from a file * @param FN name of the file to be accessed * @return true if loaded successfully, false if not */ public boolean LoadGradeList (String FN) { boolean cool = false; //erase the pre-loaded entries ArrayList <Grade> TmpList = new ArrayList (); for (Grade tmp: GradeList) { TmpList.add (tmp); } GradeList.removeAll (TmpList); TmpList = null; //end try { FileInputStream fs = new FileInputStream (SaveDir + FN + ".csv"); BufferedReader br = new BufferedReader (new InputStreamReader (fs)); String StrLine; while ((StrLine = br.readLine()) != null) { String[] Parts = StrLine.split (";"); Grade Gr = new Grade (Parts [0], Parts [1], Double.parseDouble(Parts [2])); GradeList.add(Gr); } fs.close(); cool = true; } catch (FileNotFoundException e) { System.out.println ("Δεν μπορεί να διαβαστεί το αρχείο" + SaveDir + FN); } catch (IOException e) { e.printStackTrace (); } catch (Exception e) { System.out.println (e.getMessage()); } return cool; } } //end package ex2.data; /** *Η κλάση Grade παριστά την βαθμολογία σε ένα μάθημα του προγράμματος σπουδών ενός φοιτητή. * Αφορά σε ένα άτομο και περιλαμβάνει τα κοινά στοιχεία φοιτητών και καθηγητών, * τα οποία και κληρονομούνται από τις αντιστοιχες κλασεις. * @author Ioulia Anastasiou, Iraklis Lefas, Alexandros Feidis */ public class Grade { private String Grade_StudId; private String Grade_CourseId; private double Grade; //constructor public Grade (String Grade_StudId, String Grade_CourseId, double Grade) throws Exception { this.Grade_StudId= Grade_StudId; this.Grade_CourseId = Grade_CourseId; if (Grade<0||Grade>10.0) { throw new Exception("Grade must be between 0 and 10"); //des na bei loop gia try again } this.Grade=Grade; } //Getters and Setters public String getGrade_StudId () { return Grade_StudId; } public void setGrade_StudId (String Grade_StudId) { this.Grade_StudId= Grade_StudId; } public String getGrade_CourseId() { return Grade_CourseId; } public void setGrade_CourseId (String Grade_CourseId) { this.Grade_CourseId= Grade_CourseId; } public double getGrade () { return Grade; } public void setGrade (double Grade) { this.Grade= Grade; } /** * shows all grades for a student */ public void ShowAll() { System.out.println("Student's Id...........:" + Grade_StudId); System.out.println("Course.................:" + Grade_CourseId); System.out.println("Student's Grade........:" + Grade); } /** * returns all student's grades data in one string *@return a string with all student's grades data, with additional data about the student's grades */ @Override public String toString() { String OneString; OneString = Grade_StudId + " / " + Grade_CourseId + " / " + Grade ; //OneString = super.toString() + " / " + StudId + " / " + Semester; return OneString; } } package ex2.data; /** * Η κλάση Course παριστά ένα μάθημα του προγράμματος σπουδών. Παρόλο που * είναι "κακός σχεδιασμός" τα χαρακτηριστικά της κλάσης είναι * ορισμένα χωρίς προσδιοριστή πρόσβασης, άρα είναι προσβάσιμα άμεσα μόνο * από τις κλάσεις που βρίσκονται στο ίδιο πακέτο και συγκεκριμένα * από τις {@link Professor} και {@link Student}. Φυσικά υπάρχουν οι * κατάλληλοι getters για πρόσβαση από τις κλάσεις των υπολοίπων πακέτων. * * @author Ioulia Anastasiou, Iraklis Lefas, Alexandros Feidis */ public class Course { private String CourseId; private String CourseName; private int CourseSemester; // constructors /** * * @param CourseId :course ID * @param CourseName :course name * @param CourseSemester :course's semester */ public Course (String I, String N, int Sem) { this.CourseId = I; //na dokimasw kai CourseId=I this.CourseName = N; this.CourseSemester = Sem; } // getters & setters public String getCourseId () { return CourseId; } public void setCourseId (String CourseId) { this.CourseId = CourseId; } public String getCourseName () { return CourseName; } public void setCourseName (String CourseName) { this.CourseName = CourseName; } public int getCourseSemester () { return CourseSemester; } public void setCourseSemester (int CourseSemester) { this.CourseSemester = CourseSemester; } /** * returns course's data */ public void ShowAll() { System.out.println ("COURSE DATA"); System.out.println ("=================="); System.out.println ("Course ID : " + CourseId); System.out.println ("Course Name : " + CourseName); System.out.println ("Course Semester : " + CourseSemester); } /** * returns all data in one string */ @Override public String toString () { String OneString; OneString = CourseID + " / " + CourseName + " / " + CourseSemester; return OneString; //return ID + " - " + Name + " - " + Semester; } }
Write, Run & Share Java code online using OneCompiler's Java online compiler for free. It's one of the robust, feature-rich online compilers for Java language, running the Java LTS version 17. Getting started with the OneCompiler's Java editor is easy and fast. The editor shows sample boilerplate code when you choose language as Java and start coding.
OneCompiler's Java online editor supports stdin and users can give inputs to the programs using the STDIN textbox under the I/O tab. Using Scanner class in Java program, you can read the inputs. Following is a sample program that shows reading STDIN ( A string in this case ).
import java.util.Scanner;
class Input {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter your name: ");
String inp = input.next();
System.out.println("Hello, " + inp);
}
}
OneCompiler supports Gradle for dependency management. Users can add dependencies in the build.gradle
file and use them in their programs. When you add the dependencies for the first time, the first run might be a little slow as we download the dependencies, but the subsequent runs will be faster. Following sample Gradle configuration shows how to add dependencies
apply plugin:'application'
mainClassName = 'HelloWorld'
run { standardInput = System.in }
sourceSets { main { java { srcDir './' } } }
repositories {
jcenter()
}
dependencies {
// add dependencies here as below
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
}
Java is a very popular general-purpose programming language, it is class-based and object-oriented. Java was developed by James Gosling at Sun Microsystems ( later acquired by Oracle) the initial release of Java was in 1995. Java 17 is the latest long-term supported version (LTS). As of today, Java is the world's number one server programming language with a 12 million developer community, 5 million students studying worldwide and it's #1 choice for the cloud development.
short x = 999; // -32768 to 32767
int x = 99999; // -2147483648 to 2147483647
long x = 99999999999L; // -9223372036854775808 to 9223372036854775807
float x = 1.2;
double x = 99.99d;
byte x = 99; // -128 to 127
char x = 'A';
boolean x = true;
When ever you want to perform a set of operations based on a condition If-Else is used.
if(conditional-expression) {
// code
} else {
// code
}
Example:
int i = 10;
if(i % 2 == 0) {
System.out.println("i is even number");
} else {
System.out.println("i is odd number");
}
Switch is an alternative to If-Else-If ladder and to select one among many blocks of code.
switch(<conditional-expression>) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
//code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition. Usually for loop is preferred when number of iterations is known in advance.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(<condition>){
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (<condition>);
Class is the blueprint of an object, which is also referred as user-defined data type with variables and functions. Object is a basic unit in OOP, and is an instance of the class.
class
keyword is required to create a class.
class Mobile {
public: // access specifier which specifies that accessibility of class members
string name; // string variable (attribute)
int price; // int variable (attribute)
};
Mobile m1 = new Mobile();
public class Greeting {
static void hello() {
System.out.println("Hello.. Happy learning!");
}
public static void main(String[] args) {
hello();
}
}
Collection is a group of objects which can be represented as a single unit. Collections are introduced to bring a unified common interface to all the objects.
Collection Framework was introduced since JDK 1.2 which is used to represent and manage Collections and it contains:
This framework also defines map interfaces and several classes in addition to Collections.
Collection | Description |
---|---|
Set | Set is a collection of elements which can not contain duplicate values. Set is implemented in HashSets, LinkedHashSets, TreeSet etc |
List | List is a ordered collection of elements which can have duplicates. Lists are classified into ArrayList, LinkedList, Vectors |
Queue | FIFO approach, while instantiating Queue interface you can either choose LinkedList or PriorityQueue. |
Deque | Deque(Double Ended Queue) is used to add or remove elements from both the ends of the Queue(both head and tail) |
Map | Map contains key-values pairs which don't have any duplicates. Map is implemented in HashMap, TreeMap etc. |