Suppose we want to compute the amount of money in a bank account with compound interest. If the amount of money in the account is m, the amount in the account at the end of the month will be 1.005 m. Write a recursive method that will compute the amount of money in an account after t months with a starting amount of m.
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Using MIS (10th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Problem Solving with C++ (10th Edition)
Computer Science: An Overview (12th Edition)
- I need the answer as soon as possiblearrow_forwardDo not use static variables to implement recursive methods. USING JAVA USING: // P5 public static long computePay(int day) { } You have been offered a job that pays as follows: On the first day, you are paid 1 cent, on the second day, 2 cents, on the third day, 4 cents and so on. In other words, your pay doubles every day. Write a recursive method computePay that for a given day number computes the pay in cents. Assume that you accumulate all the money that you are paid. Write a recursive method computeSavings that computes the sum that you have accumulated on a given day. Show the output of computePay and computeSavings for day number 39.arrow_forwardJava Program: Recursive Method There are n people in a room where n is an integer greater then or equal to 2. Each person shakes hands once with every other person. What is the total number of handshakes in the room? Write a recursive method to solve this problem with the following header:public static int handshake(int n)where handshake(n) returns the total number of handshakes for n people in the room. To get you started if there are only one or two people in the room, then:handshake(1)=0handshake(2)=1arrow_forward
- Write a recursive method to determine whether a String contains a 'q' not immediately followed by a 'u' (ignoring capitalization). In other words: • the word does contain at least one 'q' • and that q is followed by anything except a 'u' Carefully review the provided driver program to see example test cases. The method header is: public static boolean qNotFollowedByU(String word)arrow_forwardPlease Give answer in C# Write a recursive method which sums all the even numbers up to a given number. For example if you call it with 10, it would return 30 because 10+8+6+4+2=30 Write a RECURSIVE method called sumEven It must take in an int (the max you wish to sum to) It must return an int (the sum) If it's passed in an even number it should sum the number passed in with all the even numbers before it. For example if passed 8, it would sum 8+6+4+2=20 If it's passed an odd number it should still sum only the EVEN numbers. What we mean is that sumEven(9) should return 8+6+4+2=20. Not 9+7+5+3+1. Hint: You'll have an if statement with the base condition, an else if for even and an else if for odd. In the case of odd, just call yourself with the next lowest even number. In your main method, open a file called "Carlton.txt" for writing. Use a loop to call the method above multiple times and print a line to the file for each iteration of the loop: The sum of even numbers up to 0 is 0 The…arrow_forwardwrite a code in java (using recursion)arrow_forward
- 1. Write a recursive method expFive(n) to compute y=5^n. For instance, if n is 0, y is 1. If n is 3, then y is 125. If n is 4, then y is 625. The recursive method cannot have loops. Then write a testing program to call the recursive method. If you run your program, the results should look like this: > run RecExpTest Enter a number: 3 125 >run RecExpTest Enter a number: 3125 2. For two integers m and n, their GCD(Greatest Common Divisor) can be computed by a recursive function. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Once m is 0, the function returns n. Once n is 0, the function returns m. If neither is 0, the function can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n. Although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. Meaning your code needs to follow the given algorithm. Then…arrow_forwardUsing JAVA Recursive Power Method Write a method called powCalthat uses recursion to raise a number to a power. The method should accept two arguments: The first argument is the exponentand the second argument is the number to be raised(example”powCal(10,2)means2^10). Assume that the exponent is anonnegative integer. Demonstrate the method in a program called Recursive (This means that you need to write a program that has at least two methods: mainand powCal. The powCal method is where you implement the requirements above and the main method is where you make a method call to demonstrate how your powCalmethod work).arrow_forwardJava - Write an iterative method that calculates the SUM of all integers between 1 and a given integer N (input into the method). Write a corresponding recursive solution. (return answer, don’t print)arrow_forward
- Write a recursive method oddSum that takes a positive odd integer n and returns the sum of odd integers from 1 to n.arrow_forwardJAVA Question 2: For two integers m and n, their GCD (Greatest Common Divisor) can be computed by a recursive method. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Method body: If m is 0, the method returns n. If n is 0, the method returns m. If neither is 0, the method can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n (or m % n). The recursive method cannot have loops. Note: although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. main method: Prompt and read in two numbers to find the greatest common divisor. Call the gcd method with the two numbers as its argument. Print the result to the monitor. Example program run: Enter m: 12 Enter n: 28 GCD(12,28) = 4 And here is what I have so far, package CSCI1302;import java.util.*;public class RecursionDemo { public static void…arrow_forwardwrite a code in java (using recursion)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education