Question: Create a Part 2 subpackage p2 under the hw1 package and copy here the Course class from subpackage p1. In the p2 subpackage, create a

 Create a Part 2 subpackage p2 under the hw1 package and

copy here the Course class from subpackage p1. In the p2 subpackage,

Create a Part 2 subpackage p2 under the hw1 package and copy here the Course class from subpackage p1. In the p2 subpackage, create a public class named Grizzly, and add the following private data fields to the Grizzly class: - A private static data field named numGrizzlies of type int, representing the number of Grizzly objects that have been created. - A protected data field named id of type int, representing the ID that uniquely identifies a GGC member. - A protected data field named name, which is of type String and represents the name of a GGC member. Create the following methads in the Grizzly class: - A constructor public Grizzly (String name) that - Increments the static numGrizlies field by 1 and assigns the result to the id instance variable. - Initializes the name field with the value of the argument. - Getters for the id and name fields. - Override the equals method so that it compares only the id field and returns true if both Grizzly objects have the same id. Create a public class named Student as a subciass of the Grizzly class, and add the following private data field to the Student class: - courses, which is an Array List of Course objects each representing a course the student is enrolled in. 3 Create the following methods in the Student class: - A constructor public Student (String name) that uses the constructor of the Grizzly superclass to create a Grizzly object with the given name, and initializes the courses field to an empty list. - Getter for the courses field. - Amethod public void addCourse (Course course) that allows the student to enroll in the course represented by the Course object in the argument. The method should do the following: - Check whether the student is already enrolled in the course - this can be done by checking whether the courses list of the student already contains the name of the course. If so, print an error message "You are already enrolled in _- "where the underscore should be replaced with the name of the course. - If the student is not yet enrolled in the course, then imvoke the add method of the given Course object to add the student to the course. If the invocation succeeds, then also add the Course object to the courses list of the student. - Amethod public void dropCourse (Course course) that allows the student to drop the course represented by the Course object in the argument. Assume here that the course to be dropped is indeed a course the student is currently enrolled in. The method should remove the student from the roster of the course and remove the course from the student's course list. a list consisting onty of the names of the courses the student is enrolled in. In the Course class, - Change the type of the roster field to an Array List of Student objects. - Change the header of the add method to public boolean add (Student student) - Change the header of the remove method to public void remove (Student student) - Change the tostring() method so that it returns a string of the format Coursefnane: __ capacity: __ roster: where the underscores after "name: " and "capacity: " should be replaced with the values of the respective fields, and that after "roster: " should be replaced with a list consisting only of the nomes of the students enrolled in the course. - Override the equals method so that it compares only the name field and returns true if both Course abjects have the same name. Create a public class named Hw1Test. In the main( ) method of the class: - Create four Student objects whose names are Alice, Bob, Carol, and Daniel, respectively. Print the four Student objects. Your code should print Student {1d:1, nane: Alice, courses: []\} Student\{1d: 2 , nane: Bob, courses: []\} Student\{1d: 4, nane: Daniel, courses: []\} - Create three Course objects whose course names are "ITEC 4320", "ITEC 4700 and "ITEC 4860, respectively. Use 3 as the capacity for all three courses. Print the three Course objects. Your code should print Course\{nane: ITEC 4326 , capacity: 3 , noster: []\} 5 Course\{nane: ITEC 4706, capacity: 3, roster: []\} Course\{nane: ITEC 4860, capacity: 3, roster: []\} - Write code to simulate the following sequence of events: - Alices adds ITEC 4320, ITEC 4700 and ITEC 4700 . The second attempt to add ITEC 4700 should cause an error message "You are already enrolled in ITEC 4700. - Bob adds ITEC 4700 and ITEC 4860. - Carol adds all three courses. - Daniel adds all three courses. The attempt to add ITEC 4700 should cause an error message "ITEC 4700 is full". - Alice drops ITEC 4320. - Bob drops ITEC 4860. - Carol drops ITEC 4700. - Alice adds ITEC 4860 . - Bob adds ITEC 4320. - Daniel adds ITEC 4700. - Print the four Student objects. Your code should print Student (id: 1, name: Alice, courses: [ITEC 4700, ITEC 4860]\} Student { id: 2, name: Bob, courses: [ITEC 4700, ITEC 4320]\} Student \{id: 3, name: Carol, courses: [ITEC 4320, ITEC 4860] Student \{id: 4, name: Daniel, courses: [ITEC 4320, ITEC 4860, ITEC 4700]\} - Print the three Course abjects. Your code should print Course(name: ITEC 4320, capacity= 3, roster: [Carol, Daniel, Bob]\} Course(name: ITEC 4700, capacity: 3, roster: [Alice, Bob, Daniel]\} Course(name: ITEC 4860, capacity: 3, roster: [Carol, Daniel, Alice]) 6 Part 3 Now you will (1) create an Instructor class as a subclass of the Grizzly class and (2) modify the Course and Hw1Test classes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!