CJCoding With Joseph
15free / daySign inCreate account

A List<Integer> is not a List<Number>, so a method that takes a List<Number> refuses a list of integers. The bounded wildcard List<? extends Number> fixes that: it accepts a list of Number or of any subclass of Number. Write a method that totals any such list.

Requirements: 1. Inside Totals, write a public static method named total that takes one parameter of type List<? extends Number> and returns a double. 2. It returns the sum of every element. Read each element as a Number and get its value with doubleValue(). 3. An empty list gives 0.0.

Do NOT write a main method.

Expected output

10.0
3.75

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
GenericsMethods
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.