Question
1.The box below includes a live CompoundInterest variable, jacksAcct. There are no fees with jacksAcct. You can use this object to answer the following question.
1.The box below includes a live CompoundInterest variable, jacksAcct. There are no fees with jacksAcct. You can use this object to answer the following question. Suppose you put $10,000 in the bank, and suppose you want this sum to triple in exactly 10 years. What interest rate will allow you to turn your initial $10,000 sum into $30,000 in exactly 10 years? Write code that will calculate and then print this amount to the console. The answer that you report will be something like: .143379, or 14.34%. That's fine: just print to the console the decimal value, e.g., .143379. Enter your code in the box below.
2.The method sumNSquares calculates the sum of the squares of consecutive integers from 1 to n, where n is a positive integer. For example: If n = 5, sumNSquares should return 55, since (1*1) + (2*2) + (3*3) + (4*4) + (5*5) = 55. Write a recursive version of sumNSquares. (Remember that it's important to identify the base case so that your method will terminate properly).
3. Create a static method called sumArrays, which takes two integer arrays as input parameters. Assume these arrays have the same length. Your method should add up corresponding elements of the two arrays and put the sums into a new array which is returned as a value. Example: data1:{5, 6, 7, 8} data2:{4, 5, 6, 7} ==> {9, 11, 13, 15} public static int[] sumArrays (int[] data1, int[] data2) {
4. Write a static method named countEmptyBowls, to be added to the Bowl class, which is passed an array of Bowl objects, and returns the (int) number of Bowl objects in the array that are empty. 5. There is a bug in the sortArray method: one particular kind of input will cause a runtime error. In the box provided below, edit sortArray so that it behaves properly on these inputs. Think about this on your own for a moment before you accept hint at bottom of page. public void sortArray () { int beginP = 0; int endP = myArray.length-1; while(beginP if((myArray[beginP]!=BLUE) && (myArray[endP]!=GREEN)){ swap(beginP, endP); } while((beginP < myArray.length) && (myArray[beginP]==BLUE)){ beginP++; } while(myArray[endP]==GREEN){ endP--; } } |
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