Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing this in Java this is part 1 PART1: RECURSION OBJECTIVES -Students know how to apply the Recursion Algorithm to solve some

I need help writing this in Java this is part 1

PART1: RECURSION

OBJECTIVES

-Students know how to apply the Recursion Algorithm to solve some small Math problems

-Review how to create and call the static functions

REQUIREMENT: Write an application that allows users to select the following functions.

n! Factorial of an integer n where n provided from the keyboard

an a power n, where a and n are int numbers provided from the keyboard

Sum (n) Sum(n) = 1 + 2 + 3 + .. + n where n is an int provided from the keyboard

Sum (m, n) Sum(m, n) = m + (m+1), (m+2) + + n where m and n are int numbers provided from the keyboard

Fn Fibonacci sequence Fn = Fn 1 + Fn-2; F0 = 0 and Fn1 = 1

GCD (n,m) The greatest common divisor (GCD) of two integers m and n; m > n where m, n are provided from the keyboard

For each function, the application will ask users to enter an integer number n then print out the result in the following format:

For function 1: Factorial of 5 is 120

For function 2: 2 to the power 3 is 8

For function 3: Sum from 1 to 10 is: 55 Sum from 5 to 7 is 18 The Fibonacci at 10 is 55 Greatest Common Divisor (GCD) of 120 and 90 is 30

Notes:

-The application should allow users to continue to work on other tasks until they want to exit.

-All the above functions have to be defined as static methods in a separate class and the code should be written in the recursion algorithm

PSEUDO-CODE -Provide the pseudo-code or flowchart of main

WHAT YOU NEED TO KNOW TO DO THIS LAB

-How to write a class only includes static methods -How to create a static method: Lab7

To create a static method, you just need to add the keyword static to the heading of the method. For example: public static int factorial (int n) { .. }

-How to access static members of other class in main() To access a static method of class SP2017LAB7_StaticRecursionFunction_yourLastName, we do not need to create an object of the class SP2017LAB7_StaticRecursionFunction_yourLastName. To access a static method, we have to use the class name to call. The syntax to call a static method is, for example: to calculate the result of the factorial of 5, the syntax in the main() is: int factorialResult = SP2017LAB7_StaticRecursionFunction_yourLastName.factorial(5);

-Learn how to form a recursion algorithm with 4 steps: base case, reduce problem, general solution and recursion algorithm

-How to write the code based on the recursion algorithm -Review how to handle the menu to redisplay after finishing one task

-Review the syntax of switch statement

HOW TO DO THE PART1:

-Create the project SP2017LAB7_PART1 -Add class SP2017LAB7_StaticRecursionFunction_yourLastName then write 6 static methods by writing the code based on the recursion algorithm for each above function -Add the driver class named as SP2017LAB7_AccessStaticMemberDemo.

In main() write the code based on the above pseudo-code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions