Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider these methods: public static double f(double x) { return g(x) + Math.sq

ID: 3530188 • Letter: C

Question

Consider these methods: public static double f(double x) { return g(x) + Math.sqrt(h(x)); } public static double g(double x) { return 4 * h(x); } public static double h(double x) { return x * x + k(x) - 1; } public static double k(double x) { return 2 * (x + 1); } Without actually compiling and running a program, determine the results of the following method calls: double x1 = f(2); double x2 = g(h(2)); double x3 = k(g(2) + h(2)); double x4 = f(0) + f(1) + f(2); double x5 = f(-1) + g(-1) + h(-1) + k(-1);

Explanation / Answer

/**** please rate with 5 stars****/


1) double x1 = f(2) = g(2)+sqrt(h(2)) = 4*h(2)+sqrt(h(2))

h(2) = 4+k(2)-1 = 3+2*3 =9;

so x1= 4*9+sqrt(9) =39

2) double x2 = g(h(2)) = g(9) // h(2)=9 from above result

=4*h(9) = 4*(9*9+k(9)-1) = 4*(80+20) =400

so x2=400

3) double x3= k(g(2)+h(2)) = 2*(g(2)+h(2)+1)

= 2*(4*h(2)+h(2)+1) =2*(5*h(2)+1)

= 2*(45+1)//h(2)=9

= 92

so x3=92

4) double x4= f(0)+f(1)+f(2) = 5+18+39 = 72

5) double x5 = f(-1)+g(-1)+h(-1)+k(-1) = 0+0+0+0 =0