Classes and Objects You have already written a Java class to represent a class section for...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
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... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
A student who has a 9 A.M. class on Monday, Wednesday, and Friday mornings wants to know if the mean time taken by students to find parking spaces just before 9 A.M. is the same for each of these...
-
Assume Harley-Davidson asks your CPA firm about the SOC 2 service that your firm can provide. Write a brief memo to Gerry Berryman, Vice president of Materials Management, detailing the potential...
-
Assume that 4 years from now you will need $1,000. Your bank compounds interest at an 8% annual rate. a. How much must you deposit 1 year from now to have a balance of $1,000 4 years from now? b. If...
-
Consider the agency relationship in malpractice cases under a contingency fee system. The plaintiff (party that sues) typically pays his or her attorney about one-third of any monetary damages that...
-
Explain how the following events would affect the market for South Africa's currency, the rand, assuming a floating exchange rate. a. A rise in U.S. inflation causes many U.S. residents to seek to...
-
1. State the basis of Sinclairs challenge to the Boards decision. 2. Discuss the free speech differences between a union representation election and the election of a legislator or the enactment of...
-
Plaintiff sought to enforce against the defendant estate a promise made by his now-deceased uncle to pay Plaintiff a sum of money if Plaintiff refrained from the use of alcohol and tobacco for a...
-
Warren Ltd. has two production departments, Building A and Building B, and two service departments, Maintenance and Cafeteria. Direct costs for each department and the proportion of service costs...
-
The given code snippet is implemented using linear probing technique, what change you have to make so that the quadratic probing is implemented. @Override public boolean put(String word, String...
-
1. Calculate the internal growth rate and sustainable growth rate for S&S Air. What do these numbers mean? 2. S&S Air is planning for a growth rate of 12 percent next year. Calculate the EFN for the...
-
Consider the U.S.'s response to healthcare crises, such as COVID-19 or others, and respond to the following: What works well? What has not worked well? In what ways could the medical system be...
-
For each of the following pairs, which bond would you expect to pay a higher interest rate? Explain. a. a bond of the U.S. government or a bond of an Eastern European government b. a bond that repays...
-
If the CPI is 200 for the year 2010 and 300 today, then $600 in 2010 has the same purchasing power as ________ has today. a. $400 b. $500 c. $700 d. $900
-
Fiat money is a. a type of money with intrinsic value. b. a type of money set by government decree. c. any asset used as the medium of exchange. d. any asset used as the unit of account.
-
Lois wants to publish a local newspaper but doesnt have the financial resources to start the business. She borrows $60,000 from her friend Clark, to whom she promises an interest rate of 7 percent,...
-
An economy produces 10 cookies in year 1 at a price of $2 per cookie and 12 cookies in year 2 at a price of $3 per cookie. From year 1 to year 2, real GDP increases by a. 20 percent. b. 50 percent....
-
Look at the graphs below for Country A and Country B. Wine Wine Country A-PPF 40 Country B-PPF 10 10 40 Cheese 20 Cheese a. Which country likely has a comparative advantage in wine and which country...
-
Drainee purchases direct materials each month. Its payment history shows that 65% is paid in the month of purchase with the remaining balance paid the month after purchase. Prepare a cash payment...
-
A bank manager has been presented with a new brochure that was designed to be more effective in attracting current customers to a personal financial counseling session that would include an analysis...
-
On average, commuters in the Los Angeles, California, area require 30.0 minutes to get to work. Assume a normal distribution with a standard deviation of 5.0 minutes and a randomly selected Los...
-
According to Chebyshevs theorem, what per centage of observations should fall a. Within 2.5 standard deviations of the mean? b. Within 3.0 standard deviations of the mean? c. Within 5.0 standard...
-
Suppose that in September 2013 a company takes a long position in a contract on May 2014 crude oil futures. It closes out its position in March 2014. The futures price (per barrel) is \($88.30\) when...
-
Explain how the control variate technique is implemented.
-
A company wishes to hedge its exposure to a new fuel whose price changes have a 0.6 correlation with gasoline futures price changes. The company will lose $1 million for each 1 cent increase in the...
Study smarter with the SolutionInn App