Question: JAVA Question. This program currently fails to compile because the parameters cannot be automatically converted to Double in the statement tripleSum = item1 + item2

JAVA Question. This program currently fails to compile because the parameters cannot be automatically converted to Double in the statement tripleSum = item1 + item2 + item3;. Because TheType is bound to the class Number, the Number class' doubleValue() method can be called to get the value of the parameters as a double value. Modify tripleAvg() method to use the doubleValue() method to convert each of the parameters to a double value before adding them.

public class ItemMinimum {

public static Double tripleAvg(TheType item1, TheType item2, TheType item3) { Double tripleSum = 0.0; tripleSum = item1 + item2 + item3;

return tripleSum / 3.0; } public static void main(String[] args) { Integer intVal1 = 55; Integer intVal2 = 99; Integer intVal3 = 66; Double doubleVal1 = 14.5; Double doubleVal2 = 12.3; Double doubleVal3 = 1.75;

// Try tripleAvg method with Integers System.out.println("Items: " + intVal1 + " " + intVal2 + " " + intVal3); System.out.println("Avg: " + tripleAvg(intVal1, intVal2, intVal3) + " ");

// Try tripleAvg method with Doubles System.out.println("Items: " + doubleVal1 + " " + doubleVal2 + " " + doubleVal3); System.out.println("Avg: " + tripleAvg(doubleVal1, doubleVal2, doubleVal3) + " ");

return; } }

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!