+1 (315) 557-6473 

Recursive Functions Project Help Using Java

This is a Definition and writing of Recursive Functions Project Help completed by a java homework help specialist from our platform. It shows various steps in defining recursive functions given the type signature. It also shows how to test the respective functions for correctness.

Recursive Functions Project Help

Defining Various Sequences Given The Type Signature

• Define factorial with the following type signature:
public static double factorial ( double n)
It’s specification is given above.
• Define fibonacci with the following type signature:
public static double fibonacci( double n)
It must follow this specification:
F(0) = 0
F(1) = 1
 F(n) = F(n−1) + F(n−2)
Defining Unnamed Sequences Given The Type Signatures
• Define an unnamed sequence with the following type signature:
public static double sequence1 ( double n)
It must follow this specification:
F(0) = 2
F(1) = 2 F(n) = 2∗F(n−1)−1
• Define an unnamed sequence with the following type signature:
public static double sequence2 ( double n)
It must follow this specification:
F(0) = 5
F(1) = 5
F(n) = 3∗F(n−1)
Defining Named Sequences Given Type Signatures
• Define Hofstadter’s Q-sequence with the following type signature:
public static double hofsQ( double n)
It must follow this specification:
F(0) = 1
F(1) = 1
F(2) = 1
F(n) = F(n−F(n−1)) + F(n−F(n−2))
• Define the tetration operation with the following type signature where a is being taken to the tetration power of n:
public static double tetration( double a , double n)
It must follow this specification:
F(a,0) = 1
F(a,n) = aF(a,n−1)
Remember that ˆ in Java does not perform exponentiation but rather XOR. Use Math.pow to perform exponentiation.
• Define a mathematical sequence of your choice. The only specification that it must follow is that it must return a double and take at least one double as an argument.
Solution
public class Main {
    public static void main(String[] args) {
System.out.println("factorial(2) = " + factorial(2));
System.out.println("factorial(10) = " + factorial(10));
System.out.println("fibonacci(2) = " + fibonacci(2));
System.out.println("fibonacci(10) = " + fibonacci(10));
System.out.println("sequence1(2) = " + sequence1(2));
System.out.println("sequence1(10) = " + sequence1(10));
System.out.println("sequence2(2) = " + sequence2(2));
System.out.println("sequence2(10) = " + sequence2(10));
System.out.println("hofsQ(2) = " + hofsQ(2));
System.out.println("hofsQ(10) = " + hofsQ(10));
System.out.println("tetration(2, 3) = " + tetration(2, 3));
System.out.println("tetration(3, 2) = " + tetration(3, 2));
System.out.println("tetration(3, 3) = " + tetration(3, 3));
    }
    public static double factorial(double n) {
        if (n >= 1)
            return n * factorial(n - 1);
        else
            return 1;
    }
    public static double fibonacci(double n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1 || n == 2) {
            return 1;
        }
        return fibonacci(n - 2) + fibonacci(n - 1);
    }
    public static double sequence1(double n) {
        if (n == 0 || n == 1)
            return 2;
        return 2 * sequence1(n - 1) - 1;
    }
    public static double sequence2(double n) {
        if (n == 0 || n == 1)
            return 5;
        return 3 * sequence2(n - 1);
    }
    public static double hofsQ(double n) {
        if (n == 0 || n == 1 || n == 2)
            return 1;
        return hofsQ(n - hofsQ(n - 1)) + hofsQ(n - hofsQ(n - 2));
    }
    public static double tetration(double a, double n) {
        if (n == 0)
            return 1;
        return Math.pow(a, tetration(a, n - 1));
    }
    // your chosen math sequence goes here
}
Testing the Functions
Here is some output from these functions that you can use to make sure your functions are correct:
fibonacci(2) = 1.0
fibonacci(10) = 55.0
sequence1(2) = 3.0
sequence1(10) = 513.0
sequence2(2) = 15.0
sequence2(10) = 98415.0
hofsQ(2) = 1.0
hofsQ(10) = 6.0
tetration(2,3) = 16.0
tetration(3,2) = 27.0
tetration(3,3) = 7.625597484987E12
Recursive Functions Project Help Using Java
Related Blogs

Java tutors in the USAJava is a computing language designed for the development of desktop and mobile applications, embedded systems, and the processing of big data. Introduced in 1995, Java is so much like C and C + + but easier to use because it enforces the object-oriented programming model. One ...

2020-07-25
Read More

Are You Troubled with Your Java Programming Homework?Java programming language was derived from C but is more flexible and compatible with multiple platforms. Java’s true power lies within people’s ability to manipulate the objects and variables within a program, which is why it is considered an obj...

2020-08-12
Read More

Why You May Seriously Need Help With Java Programming Homework?How well are you conversant with Java programming? Given Java homework, can you handle it correctly for impressive results? Well, if you can not, there is a need to seek help with the Java programming homework. Also, even after get...

2020-08-12
Read More

Why C# Programming Homework Help Is Better Than JavaThere are a lot of similarities between Java and C#, and the responsibility of this can be placed on Sun. Microsoft used to have its own implementation of Java which had some changes so that you could access Windows fully but Sun sued and so Micros...

2020-08-12
Read More

Improving Your Java Coding Skills by Learning How to DebugIt is no secret that most students spend a lot of time debugging rather than writing their Java code. In most universities and colleges, professors will only teach you the concepts of coding in Java and not how to fix the defects in your soft...

2020-08-12
Read More