Question

note: the language should be java on netbeans. please solve the question complete. Objective: The students...

note: the language should be java on netbeans.

please solve the question complete.

Objective: The students will learn how to work with recursion and improve their problem solving skills.

Problem 1: Create an interactive Java Application that has a method to calculate the value of e x = 1 + (x / 1!) + (x2 / 2!) + (x3 / 3!) + … + (xn / n!) Where n and x are supplied by the user. Your must call 2 recursive methods (1 for factorial and another one for power (do not use pow method available in java).

Create an interactive Java Application that has a recursive method vowels that returns the number of vowels in a string.

Create an interactive Java Application that has a recursive method reverse that print a String in reverse.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Test {
        public static int fact(int n) {
                if(n <= 1) {
                        return 1;
                }
                return n * fact(n-1);
        }
        public static int power(int x, int n) {
                if(n == 0) {
                        return 1;
                }
                return x * power(x, n-1);
        }
        
        public static void main(String[] args) {
                
                Scanner in = new Scanner(System.in);
                
                int n, x;
                System.out.println("Enter value of x: ");
                x = in.nextInt();
                System.out.println("Enter value of n: ");
                n = in.nextInt();
                
                double value = 0;
                
                for(int i=0; i<=n; i++) {
                        int num = power(x, i);
                        int den = fact(i);
                        value += (num/(double)den);
                }
                
                System.out.println("Value of e^x is " + value);
                
                in.close();
        }
}
**************************************************

Please ask each part separately, since they require quite some time to complete and it is not possible to answer everything in this particular answer.. Please post on separate threads, so that we can properly answer them. Thanks!

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
note: the language should be java on netbeans. please solve the question complete. Objective: The students...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to...

    Java language Any use of java.util.LinkedList is prohibited Objective: The goal of this assignment is to practice recursion. ignment: The assignment requires writing recursive methods for some linked list operations. The use of loops in the recursive methods is strictly prohibited in this assignment. That is, you cannot use for, while, and do-while in the recursive methods you will write. You can only use a loop when you will initiate values for a linked list in the main method. You...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the...

    In JAVA using Netbeans Create a method called sumLastValues that will produce the sum of the last two values in an int variable. Your method should take as a parameter the integer to extract the last two values from. Your method should check to make sure that the int has at least two digits in it. If it does not your method should simply return-1 If it does extract the last two digits return their sum NOTE You are not...

  • Write an application with two classes USING JAVA METHODS HAVE TO BE CREATED USING RECURSION. First...

    Write an application with two classes USING JAVA METHODS HAVE TO BE CREATED USING RECURSION. First class named Recursion has the following three recursive methods: // PRECONDITION n is positive integer. Method sumTerms returns sum of terms that are // reciprocal values of first n integers, with  alternating signs.      // For example,  sumTerms(7) returns  the following:  1/1 – 1/2  + 1/3 – 1/4  + 1/5 -1/6 + 1/7. // Terms with an odd denominator have positive sign, and terms with even denominator have // negative sign.  ...

  • A java program for this question please! Recursion: A word is considered elfish if it contains...

    A java program for this question please! Recursion: A word is considered elfish if it contains the letters: e, l, and f in it, in any order. For example, we would say that the following words are elfish: whiteleaf, tasteful, unfriendly, and waffles, because they each contain those letters. Write a recursive method called elfish(), that, given a word, tells us whether or not that word is elfish. The signature of the method should be: public static boolean elfish(String word)...

  • I just need to add comment for the code blow. Pleas add comment for each method...

    I just need to add comment for the code blow. Pleas add comment for each method and class if comments left out. package exercise01; /*************************************************************************** * <p> This program demonstrates the technique of recursion and includes * recursive methods that are defined for a variety of mathematical * functions. *    * <br>A recursive method is one that directly or indirectly calls itself * and must include: * <br>(1) end case: stopping condition * which terminates/ends recursion * <br>(2) reduction:...

  • Then create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following...

    Then create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines. Modify the example in Horstmann Section 5.9, pp. 228-230 so that the triangle displays “in reverse order” as in the example below, which allows the user to set the number of lines to print and the String used for printing the triangle. Use a method to prompt the user for the number of lines (between 1 and 10) to print. This method should...

  • please use java application to solve methods: 5,6,10,12,13 (no need for the rest) Problem1: Create a...

    please use java application to solve methods: 5,6,10,12,13 (no need for the rest) Problem1: Create a new Java Application that has the following methods: 6 A method that generate a binary search tree (BST) where the number of nodes and the range of the values are 1. from a file. 2. A recursive method to print the BST in preorder traversal 3. A recursive method to print the BST in post-order traversal 4. A recursive method to print the BST...

  • create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines....

    create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines. Modify the example in Horstmann Section 5.9, pp. 228-230 so that the triangle displays “in reverse order” as in the example below, which allows the user to set the number of lines to print and the String used for printing the triangle. Use a method to prompt the user for the number of lines (between 1 and 10) to print. This method should take...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT