Managing Lists of Things For this program you will be asked to add functions to
ID: 3601983 • Letter: M
Question
Managing Lists of Things
For this program you will be asked to add functions to a list management program. You may build on the work you did for program #1 in which you created a list of Things. Of course you may start fresh but you may be able to save some time if you build on program #1. Requirements borrowed from program #1: You may already have implemented the following functions in program #1 but if not, you do need to provide them for program #2. • Implement the sort of Thing to be stored on your list as a class. The object/class must have the following characteristics: o At least 5 attributes/characteristics o At least one numeric attribute o At least one String attribute o One String attribute should be usable as a search key • Create the list by implementing a collection of the objects using an array. You may NOT use the library class ArrayList. • Allow the user to enter data and store it in the list. • Display the complete list, reflecting all changes. • Check for errors such as entering text in a numeric field or entering more values than can be held in the array of objects. Gracefully recover from any problems without crashing the program. (See Appendix C for more on exception handling.) • Use of a graphical user interface such as JavaFX is required. New requirements: • Implement Cloneable and clone() for your Thing class. Use deep copying appropriately. • Implement and use the Comparable interface. • (Extra credit) Implement and use an iterator over your list. Use the Iterator interface correctly. Or you may choose to use the Iterable interface instead.
Explanation / Answer
which will take a list of numbers as input and return the average value in that list. Many people seem to think that they are supposed to find each student's average in this function. Thus, many people have a variation of the following code:
Alternatively, some people get the average of each subject and try to return that like so:
Now obviously these are just two examples of many different solutions people try. But they are representative of the logic of many people. I will now try to explain where this logic is flawed.
Let us start with the def statement. I have noticed many people write, as I have above def average(student). This tells me that people are incorrectly assuming that average will be passed a dictionary/student and/or that this function should return a student's average. Neither of these are the case. The correct def statement looks something like def average(list_of_numbers). average will be passed a list of numbers, not a dict or student.
Other errors stem from similarly faulty logic, and by misunderstanding what the lesson is asking you to do. This lesson is asking you to make a general function that will function anywhere and in any context in which we need to find an average value in a list of numbers. In a later lesson, you will use this function to find the grade average of each student. But for now we are making a generalized function for any situation.
Here are some valid inputs and outputs for average()
If your code works for all three of those inputs, you should be fine.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.