id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

jebbert@volusia.k12.fl.us > test2024_04_16_SLHL_formula
prev  |  next  |  chance

YOUR SOLUTION TO THIS PROBLEM MUST BE RECURSIVE!!! Write a method that RECURSIVELY computes the nth term of a recursively-defined function. The x-sub-zero term of the function is equal to 'initVal'. To find the x-sub-(n-1) term of the function, you compute 'mult'*(x-sub-n)^'pow'+'add' (following the correct order of operations. Note that "x-sub-n" means an x with a subscript of n, I just had no way to make the subscript in these directions! Note that some of the variables and the returned value are of type double. The value of 'n' indicates which x-sub-n you are looking for. For example, if 'n' is 5 you are looking for x-sub-5. Suppose you call the method with the following parameter list: (1.5,0.5,2,-1,2) This means that the x-sub-zero value is 1.5. The x-sub-1 value is 0.5*(1.5)^2-1 = 0.125 Then the x-sub-2 value is 0.5*(0.125)^2-1 = -0.9921875 Here is an easier to follow example: Suppose you call the method with the following parameter list: (3.5,1,1,10,3) This means that the x-sub-zero value is 3.5. The x-sub-1 value is 1*(3.5)^1+10 = 13.5 Then the x-sub-2 value is 1*(13.5)^1+10 = 23.5 Finally the x-sub-3 value is 1*(23.5)^1+10 = 33.5 Look at the test data for additional examples. As preconditions you may assume that 'n' is non-negative and that 'pow'>0. I suggest using a helper method so your recursive call does not need the full name of the method, but this is optional. However, a recursive solution IS required. YOUR SOLUTION TO THIS PROBLEM MUST BE RECURSIVE!!!


test2024_04_16_SLHL_formula(1.25, 3, 1, 1.5, 5) → 485.25
test2024_04_16_SLHL_formula(1, 5, 1, 0, 6) → 15625.0
test2024_04_16_SLHL_formula(2, 1, 2, 0, 4) → 65536.0

...Save, Compile, Run (ctrl-enter)

public double test2024_04_16_SLHL_formula(double initVal, double mult, int pow, double add, int n) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 410

Copyright Nick Parlante 2017 - privacy