Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Classes and Objects You have already written a Java class to represent a class section for a course like SOC 300, but you must

Classes and Objects You have already written a Java class to represent a class section for a course like SOC 300 but you must wonder, what about the students who have enrolled in it? Well take care of that now by creating another class called StudentEnrollee and adding an attribute of an ArrayList of this type to class section. Now the complete set of attributes will be 1.CRN: 10059 2. Department SOC 3.Course number 300 4.Instructional mode : Online 5. Meeting days N/A 6. Meeting times: N/A 7. Capacity 60 8. Enrollment: 60 9. Instructors ID:122 10. Enrollee list (an ArrayList of student enrollees) We need to create a StudentEnrollee class which has these attributes Student ID grade (For simplicity lets use numbers like 4, 3, 2, 1 and 0.) We dont include student attributes like lastName, firstName, majorCode, etc. because we assume that the database designers have correctly designed these tables to eliminate redundancy. Therefore, they represent student in an enrollee list by its ID which points to a record in a separate student table that contains the complete set of student attributes Because these attributes, like most data attributes in object-oriented applications, are private they need setter and getter methods. They must also have a no parameter constructor, a constructor that accepts parameters for both attributes, and a toString method Once youve written the Java file for the StudentEnrollee class, you can add an ArrayList of student enrollees to the class section class. We use an ArrayList because it has the ability to expand to accommodate new elements, as opposed to an array which has a fixed size We declare ArrayLists this way List Class? nameOfList = new ArrayListClass (optional number of elements) For instance, to create an empty ArrayList of objects of a class named Book: List Book booklistnew ArrayList-Book0 To create an ArrayList of objects of a Book class which can initially hold 10 Book objects

Classes and Objects You have already written a Java class to represent a class section for a course like SOC 300, but you must wonder, what about the students who have enrolled in it? We'll take care of that now by creating another class called StudentEnrollee and adding an attribute of an ArrayList of this type to class section. Now the complete set of attributes will be: 1.CRN: 10059 2. Department: SOC 3.Course number: 300 4. Instructional mode: Online 5. Meeting days: N/A 6. Meeting times: N/A 7. Capacity: 60 8. Enrollment: 60 9. Instructor's ID: 122 10. Enrollee list (an ArrayList of student enrollees) We need to create a StudentEnrollee class which has these attributes: Student ID grade (For simplicity let's use numbers like 4, 3, 2, 1 and 0.) We don't include student attributes like lastName, firstName, majorCode, etc. because we assume that the database designers have correctly designed these tables to eliminate redundancy. Therefore, they represent student in an enrollee list by its ID which points to a record in a separate student table that contains the complete set of student attributes. Because these attributes, like most data attributes in object-oriented applications, are private, they need setter and getter methods. They must also have a no parameter constructor, a constructor that accepts parameters for both attributes, and a toString method. Once you've written the Java file for the StudentEnrollee class, you can add an ArrayList of student enrollees to the class section class. We use an ArrayList because it has the ability to expand to accommodate new elements, as opposed to an array which has a fixed size. We declare ArrayLists this way: List nameOfList = new ArrayList (optional number of elements); For instance, to create an empty ArrayList of objects of a class named Book: List bookList = new ArrayList (); To create an ArrayList of objects of a Book class which can initially hold 10 Book objects: To create an ArrayList of objects of a Book class which can initially hold 10 Book objects: List bookList = new ArrayList (10); Now the class section class needs several new methods related to the enrollee list: -A method, let's call it addStudent, to add an individual student to the enrollee list -A method to locate the ArrayList element which holds (actually points to) the enrollee -object that has a particular student ID -A method to withdraw a student -A method to assign a grade to a student -A method to display a list of enrollees Unless you really want to do extra work, don't add a parameter for the ArrayList of students to the ClassSection constructor. We can just add them one at time using an addStudent method described later. This more closely resembles the actual enrollment process anyway. The next several paragraphs describe some activities which you will probably find unfamiliar and complex. The sample code in this module demonstrates these techniques. Study it carefully. There is a slight complication in working with our ArrayList. We cannot interact with it directly because it is a private member of Class Section. Therefore, we cannot simply perform an action like adding adding a student by invoking the add method of the ArrayList class. Instead, we must create a public addStudent method of the ClassSection class which will pass the StudentEnrollee object to the add method of the ArrayList class. Likewise, we cannot withdraw a student by simply invoking the remove method of ArrayList, We must create a withdrawStudent method that invokes the remove method of ArrayList. In order to either withdraw or assign grades to a student, we must first locate her element in the ArrayList. We must write a method that does this. It will accept a student ID as a parameter then loop through the ArrayList until it finds the object which has it. Then it can return the index of this element. If no element has a particular ID, this method should return a negative one (-1) to indicate that the search failed. Withdrawing a student involves first locating the index of the object with the ID you want to delete then using the remove method of the ArrayList class to delete it. To assign a grade to an enrollee, invoke the setGrade method of the enrollee class via the object with the index of the student whose grade you want to change. Again, you must first find the index belonging to that student. You should change the getEnrollment method of the class section class to return the number of enrollees in the ArrayList by invoking its size method. Now for the driver program: create an instance of a ClassSection class that accepts hard coded values for all parameters. Then do the following: Display the results of the ClassSection object's toString method, just as you did in the previous project. Next add several students (give them IDs ranging from 1 to 4 and this grades of 0 because the semester just strted and they haven't earned any grades yet) to the enrollee ArrayList using the method that accepts one student. After adding the students, display the enrollee list. Change the grades of the students to 1, 2, 3 and 4. Display the enrollee list again. Now delete a student then display the enrollee's again.

Step by Step Solution

3.48 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

The class segment is not displayed in the query but its attribute is provided However the caste division has only been mentioned in relation to the fu... 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_2

Step: 3

blur-text-image_3

Document Format ( 2 attachments)

PDF file Icon
606ad568624b0_48592.pdf

180 KBs PDF File

Word file Icon
606ad568624b0_48592.docx

120 KBs Word File

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

Introduction To Business Statistics

Authors: Ronald M. Weiers

7th Edition

978-0538452175, 538452196, 053845217X, 2900538452198, 978-1111524081

More Books

Students explore these related Programming questions