Page 1 of 1

University - name: String + University(name: String, size: int) + addDepartment(d: Department):void + getNumberOfDepartm

Posted: Fri May 20, 2022 10:05 am
by answerhappygod
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 1
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 1 (47.95 KiB) Viewed 38 times
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 2
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 2 (76.06 KiB) Viewed 38 times
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 3
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 3 (80.4 KiB) Viewed 38 times
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 4
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 4 (56.09 KiB) Viewed 38 times
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 5
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 5 (46.22 KiB) Viewed 38 times
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 6
University Name String University Name String Size Int Adddepartment D Department Void Getnumberofdepartm 6 (54.12 KiB) Viewed 38 times
University - name: String + University(name: String, size: int) + addDepartment(d: Department):void + getNumberOfDepartments(): int + printReport(filename: String): void + saveUniversity(filename: String):void + load University(filename: String):void + display University(): void -depts Department -name: String + Department(name: String) + addStudent(s: Student): void + getName(): String + getTop100): Student) + saveDepartment(): void + loadDepartment(): void + displayDepartment(): void - students 200 Student name : String gpa: double + Student(name: String, spa: double) + getters + toString(): String Class Student ATTRIBUTES: • name: the name of the student. - spa: the GPA of the student. METHODS: + Student(name: string, gpa: double): Constructor. The gpa must be between 1.00 and 5.00. If not, the constructor throws an exception (IllegalArgumentException) with the message "ERROR: GPA must be between 1 to 5." getters: for name and gpa. toString(): returns the following string <Name> (<gpa>)

Class Department ATTRIBUTES: • name: the name of the department. O METHODS: Department(name: string): Constructor. It calls loadDepartment() to load all the students. If any exception was thrown, print the exception object. addStudent(s: Student): adds a student to the department. Prints "Student <Student.toString()> added" when added, or "Student Student.toString()> was not added." It calls save Department() to load all the students. If any exception was thrown, print the exception object. + getTop100): this method returns an ordered array of top students. The array size is 10. The top 10 students are the students with the best GPAs in the department. The array must be sorted by spa (the best spa is in index 0 and so on). If the department doesn't have 10 students, the rest of the array is will be filled with nulls. saveDepartment(): this method writes all the department's students into the file "<name>.dat". It throws all IOExceptions. + load Department(): this method removes all existing student from the department. Then reads the file "<name>.dat" and fills the students' array with students and updates the number of students. If FileNotFoundException is thrown, it handles it by printing "New department <Name> is ready." If ClassNotFoundException is thrown, it handles it by deleting the file via File object.delete() then prints "Incorrect file. It was deleted. New department <Name> is ready" it throws other IOExceptions. displayDepartment(): prints the department name, number of students in the department, the prints all the students info. Class University O ATTRIBUTES: - name: the name of the University. o METHODS: + University(name: string, size:int): Constructor. It uses the method load University() to load all the departments. The filename should be "<name>.dat". If any exception was thrown, print the exception object. + addDepartment(d: Department): adds a department to the universityPrints "Department <Department.getName()> added" when added, or "Department <Department.getName()> was not added." It uses the method save University) to load all the departments. The filename should be "<name>.dat". If any exception was thrown, print the exception object.

getNumberOfDepartments(): return the number of departments in the university. printReport(filename: String): this method write into the file filename in a human-readable format (as String). It writes the top 5 students from every department along with their department's name in the University as follows: University <name> top 5 students in each department: 1- <Student.toString> from department DepartmentA.name> 2- <Student.toString> from department DepartmentA.name> 3- Student.toString> from department DepartmentA.name> 1- Student.toString> from department DepartmentB.name> 2- <Student.toString> from department DepartmentB.name> 4- <Student.toString> from department <DepartmentZ.name> 5- <Student.toString> from department Department2.name> save University(filename: String): this method writes all the department's names (NOT the object, just the name) into the file filename. It throws all IOExceptions. load Universityo: this method removes all existing departments from the university. Then reads the file filename. It then creates Department objects with these names and fills the department's array with them and updates the number of departments. If FileNotFoundException is thrown, it handles it by printing "New university <Name> is ready." It throws other IOExceptions. display University(): prints the university name, number of departments, the displays all the departments. Note: you need to implement interface Serializable if you want to use ObjectOutputStream. Note 2: String can be written into a file using ObjectOutputStream.writeObject() AssignmentExtra.java public class AssignmentExtra { public static void main(String[] args) { University u = new University("KSU", 10); if (u.getNumberOfDepartments() == ) { Department di = new Department("Computer Science"); d1.addStudnet(new Student("Ali", 3.75)); d1.addStudnet(new Student("Fahad", 3.5)); d1.addStudnet(new Student("Majed", 4.75)); d1.addStudnet(new Student("Saad", 4.15)); di.addStudnet(new Student("Khalid", 2.75)); di.addStudnet(new Student("Musa", 3.25); d1.addStudnet(new Student("Nasser", 4.00));

Department d2 = new Department("Information Systems"); d2.addStudnet(new Student ("Raad", 3.85)); d2.addStudnet(new Student("Faisal", 4.75)); d2.addStudnet(new Student("Hesham", 4.25)); d2.addStudnet(new Student("Feras", 4.05)); d2.addStudnet(new Student ("Muayd", 2.99)); Department d3 = new Department ("Computer Engineering"); d3.addStudnet(new Student("Talal", 2.75)); d3.addStudnet(new Student("Tareq", 3.95)); d3.addStudnet(new Student("Abdullah", 3.85)); d3.addStudnet(new Student("Abdulrahman", 4.85)); d3.addStudnet(new Student("Abdulaziz", 2.70)); d3.addStudnet(new Student("Ahmad", 3.33)); Department d4 = new Department("Software Engineering"); d4.addStudnet(new Student("Bader", 3.04)); d4.addStudnet(new Student("Ibrahim", 3.76)); d4.addStudnet(new Student("anal", 4.80)); d4.addStudnet(new Student("Omar", 3.96)); u.addDepartment(di); u.addDepartment (d2); u.addDepartment (43); u.addDepartment(04); } u.displayUniversity(); u.printReport("top_students.txt"); } Sample Run(First time) New university KSU is ready. New department computer Science is ready. Student Ali( 3.75 ) was added. Student Fahad(3.5) was added. Student Majed( 4.75 ) was added. Student Saad( 4.15 ) was added. Student Khalid( 2.75 ) was added. Student Musa( 3.25 ) was added. Student Nasser( 4.0) was added. New department Information Systems is ready. Student Raad( 3.85 ) was added. Student Faisal( 4.75 ) was added. Student Heshan ( 4.25 ) was added. Student Feras( 4.05) was added. Student Muayd( 2.99) was added. New department Computer Engineering is ready.

Student Talal( 2.75 ) was added. Student Tareq( 3.95 ) was added. Student Abdullah( 3.85 ) was added. Student Abdulrahman( 4.85 ) was added. Student Abdulaziz( 2.7 ) was added. Student Ahmad( 3.33 ) was added. New department Software Engineering is ready. Student Bader( 3.04 ) was added. Student Ibrahim( 3.76 ) was added. Student Jamal( 4.8 ) was added. Student Omar( 3.96 ) was added. Department Computer Science was added. Department Infornation Systems was added. Department Computer Engineering was added. Department Software Engineering was added. University KSU, Number of departments: 4 Department Computer Science, Number of students: 7 Ali( 3.75 ) Fahad( 3.5) Majed( 4.75 ) Saad( 4.15 ) Khalid( 2.75 ) Musa( 3.25) Nasser( 4.0) Department Information Systens, Number of students: 5 Raad( 3.85 ) Faisal( 4.75 ) Hesham( 4.25 ) Feras( 4.85 ) Muayd( 2.99 ) Department Computer Engineering, Number of students: 6 Talal( 2.75 ) Tareq( 3.95 ) Abdullah( 3.85 ) Abdulrahman ( 4.85 ) Abdulaziz( 2.7 ) Ahmad( 3.33 ) Department Software Engineering, Number of students: 4 Bader( 3.04 ) Ibrahim 3.76 ) Jamal( 4.8) Omar( 3.96 ) Second Run University KSU, Number of departments: 4 Department Computer Science, Number of students: 7 Ali( 3.75 ) Fahad( 3.5) Majed( 4.75 ) Saad( 4.15) Khalid 2.75

Musa( 3.25) Nasser( 4.0) Department Infornation Systems, Number of students: $ Raad( 3.85 ) Faisal( 4.75 ) Hesham( 4.25 ) Feras ( 4.05 ) Muayd( 2.99) Department computer Engineering, Number of students: 6 Talal( 2.75 ) Tareq( 3.95 ) Abdullah( 3.85 ) Abdulrahman ( 4.85 ) Abdulaziz( 2.7 ) Ahmad( 3.33 ) Department Software Engineering, Number of students: 4 Bader( 3.84 ) Ibrahim( 3.76 ) Jamal( 4.8 ) Omar( 3.96 ) top_students.txt University KSU top 5 students in each department 1- Majed ( 4.75 ) from department Computer Science 2- Saad( 4.15 ) from department Computer Science 3- Nasser( 4.0 ) from department Computer Science 4- Ali(3.75 ) from department computer Science 5- Fahad( 3.5 ) from department Computer Science 1- Faisal( 4.75 ) from department Information Systems 2- Hesham( 4.25 ) from department Information Systems 3- Feras( 4.05 ) from department Information Systems 4- Raad( 3.85 ) from department Information Systems 5- Muayd ( 2.99 ) from department Information Systems 1. Abdulrahman( 4.85 ) from department Computer Engineering 2- Tareq( 3.95 ) from department Computer Engineering 3- Abdullah( 3.85 ) from department Computer Engineering 4- Ahmad (3.33 ) from department Computer Engineering 5- Talal ( 2.75 ) from department Computer Engineering 1. Jamal( 4.8 ) from department Software Engineering 2- Omar( 3.96 ) from department Software Engineering 3- Ibrahim( 3.76 ) from department Software Engineering 4- Bader ( 3.04 ) from department Software Engineering