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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started