Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2: Download and import the attached file Homework2Q2.zip to your Eclipse workspace (Click File > Import > General > Existing Projects into workspace >

Question 2: Download and import the attached file Homework2Q2.zip to your Eclipse workspace (Click File > Import > General > Existing Projects into workspace > Select archive file). Continue on Homework1Q2 and reuse your classes from that Eclipse project. Once again, you will get one runner class in the default package that has errors. Fix the errors by creating the corresponding missing classes without modifying Runner.java. Once done, the output of your program should look exactly like the following

attached file Homework2Q2.zip:

import qa.edu.qu.cmps251.homework2q2.CompetitionGroup; import qa.edu.qu.cmps251.homework2q2.Student; import qa.edu.qu.cmps251.homework2q2.Supervisor;

public class Runner {

public static void main(String[] args) { //Create a student //Parameters here are: Name, age, number of courses enrolled in, and academic year (first year, second year, etc) //Pay attention that the ID is auto generated Student s1 = new Student("Abdulla Al-Naimi", 20, 6, 2); //Create second student (Aisha) Student s2 = new Student(); //Set number of enrolled classes for Aisha to 4 s2.setNumEnrolledClasses(4); //Set the age of Aisha to 23 s2.setAge(23); //Let's add two seniors Student s3 = new Student("Ahmad Hamad", 24, 2, 4); Student s4 = new Student("Saleh Al-Badi", 22, 4, 4); //print all students in system Student.printHeader(); s1.printStudentInfo(); s2.printStudentInfo(); s3.printStudentInfo(); s4.printStudentInfo(); System.out.println(" total number of students is: " + Student.totalNumOfStudents); System.out.println(""); //Homework 2 particular code starts here System.out.println("Adding competition supervisors to the system "); //Each supervisor has (a) a name and (b) a specialization Supervisor supervisor1 = new Supervisor("Dr. Ahmad AlAnsari", "Virtual Reality"); Supervisor supervisor2 = new Supervisor("Dr. Moza Al-Kaabi", "Wireless Communication"); //Let's print them out supervisor1.printInfo(); System.out.println(""); //add an empty line between them supervisor2.printInfo(); System.out.println(" Creating a new competition group with three students, then printing their information "); //Each group in the competition must have a group name, an assigned supervisor, //and a maximum of three students CompetitionGroup compGroup = new CompetitionGroup("The Titans", supervisor1); //let's add the students compGroup.addStudent(s1); compGroup.addStudent(s3); compGroup.addStudent(s4); compGroup.addStudent(s2); //notice this line gives an error message ! Can't have more than 3 System.out.println(""); //printing the group's information compGroup.printInfo(); System.out.println(" Creating a second competition group and printing its information "); //Let's create another competition group with only Aisha in it and Dr. Moza is the supervisor CompetitionGroup compGroup2 = new CompetitionGroup("SuperPower X", supervisor2); //Let's print the information. We see that this group has no students :( compGroup2.printInfo(); System.out.println(" No student! Let's add Aisha and print again "); //Let's set the first student to be Aisha compGroup2.addStudent(s2); //Let's print again? compGroup2.printInfo();

System.out.println(" Let's change the supervisor of group 1 "); //Group 1 decided to switch their supervisor to Dr. Moza. compGroup.setSupervisor(supervisor2); //Print Group 1 compGroup.printInfo(); //Let's remove "Ahmad Hamad" from first group. System.out.println(" Removing Ahmad Hamad from first group "); boolean isRemoved = compGroup.removeStudent("Ahmad Hamal"); System.out.println("isRemoved first time is: " + isRemoved + " "); //notice isRemoved is false here because Hamal doesn't exist ! Let's try again isRemoved = compGroup.removeStudent("Ahmad Hamad"); if (isRemoved) System.out.println("Success! Student is removed "); else System.out.println("Failure. Couldn't remove student "); //one last print compGroup.printInfo(); }

}

the output

ID Name Age CH Academic Year ------------------------------------------------------------------ 1 Abdulla Al-Naimi 20 18 Sophomore 2 Aisha AlQahtani 23 12 Freshman 3 Ahmad Hamad 24 6 Senior 4 Saleh Al-Badi 22 12 Senior total number of students is: 4 Adding competition supervisors to the system Name: Dr. Ahmad AlAnsari Specialty: Virtual Reality Name: Dr. Moza Al-Kaabi Specialty: Wireless Communication Creating a new competition group with three students, then printing their information ERROR: Cannot add more than three students Group name Supervisor No. of students ========== ========== =============== The Titans Dr. Ahmad AlAnsari 3 Supervisor information: Name: Dr. Ahmad AlAnsari Specialty: Virtual Reality Group members: ID Name Age CH Academic Year ------------------------------------------------------------------ 1 Abdulla Al-Naimi 20 18 Sophomore 3 Ahmad Hamad 24 6 Senior 4 Saleh Al-Badi 22 12 Senior Creating a second competition group and printing its information Group name Supervisor No. of students ========== ========== =============== SuperPower X Dr. Moza Al-Kaabi 0 Supervisor information: Name: Dr. Moza Al-Kaabi Specialty: Wireless Communication Group members: ID Name Age CH Academic Year ------------------------------------------------------------------ No student! Let's add Aisha and print again Group name Supervisor No. of students ========== ========== =============== SuperPower X Dr. Moza Al-Kaabi 1 Supervisor information: Name: Dr. Moza Al-Kaabi Specialty: Wireless Communication Group members: ID Name Age CH Academic Year ------------------------------------------------------------------ 2 Aisha AlQahtani 23 12 Freshman Let's change the supervisor of group 1 Group name Supervisor No. of students ========== ========== =============== The Titans Dr. Moza Al-Kaabi 3 Supervisor information: Name: Dr. Moza Al-Kaabi Specialty: Wireless Communication Group members: ID Name Age CH Academic Year ------------------------------------------------------------------ 1 Abdulla Al-Naimi 20 18 Sophomore 3 Ahmad Hamad 24 6 Senior 4 Saleh Al-Badi 22 12 Senior Removing Ahmad Hamad from first group isRemoved first time is: false Success! Student is removed Group name Supervisor No. of students ========== ========== =============== The Titans Dr. Moza Al-Kaabi 2 Supervisor information: Name: Dr. Moza Al-Kaabi Specialty: Wireless Communication Group members: ID Name Age CH Academic Year ------------------------------------------------------------------ 1 Abdulla Al-Naimi 20 18 Sophomore 4 Saleh Al-Badi 22 12 Senior

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Describe the nature of negative messages.

Answered: 1 week ago