Description
- Section 5: Recursion
- Conclusion
- References
- New Content
- Create a pseudo code routine that will ask the user for a number, and then using recursion, generate the factorial of that number.
- Create fully documented pseudo code to prompt for a number and generate the factorial, including error and bound checking.
- Create a test plan to show how the program runs and can be executed.
Unformatted Attachment Preview
Purchase answer to see full attachment
Explanation & Answer
Attached.
Surname1
Name
Tutor
Course
Date
Recursion
Recursion in Java programming is simply calling a function from another which
immediately suggests that another function might call itself. In Java an example of recursion is
factorial functions. i.e n!=n*(n-1)*(n-2)*…*2*1.here I will use Factorial.java to run it.
Recursion gives the plan which is needed: Firstly, we can move n−1 which is top discs to an
empty pole, then followed by moving the largest disc to next empty pole, then we can complete
this job by moving the n−1 onto the largest discs.
1. Pseudocode is given below:number = print("Enter a number")
result = computeFactorial(number)
display("Factorial is", result)
long int computeFactorial(int n){
if (n >= 1)
return n*computeFactorial(n-1);
else
return 1;
}
Surname2
2. Create fully documented pseudo code to prompt for a number and generate the factorial,
including error and bound checking
number = print("Enter a number")
result = computeFactorial(number)
display("Factorial is", result)
public long computeFactorial(int n){
long result = -1;
if (n < 0){
System.out.println("Cannot compute Factorial for Negative Numbers");
}else if (n > 100){
System.out.println("Number is too large to compute Factorial");
}else if (n == 0){
result = 1L;
}else{
result = n * computeFactorial(n - 1);
}
return result;
Surname3
}
Q3) Create a test plan to show how the program runs and can be executed.
In this case we would like to test the functionality of the coding in pseudo code properties.
Factorial in computer is very essential when its loops are to be executed. We would like to
ensure that every function in the ode runs.
All functions like should be able to work out in every disc from top n-1 to the largest disk.
In order to run this coding we are supposed to use either net beans or eclipse. Other compilers
like Visual Studio can be used to run the code.
The UI testing for this code should be efficient and simple. The code is compliant with all
standard graphical interfaces
The code is compatible or is supported by other OS like windows, linux, android and Mac OS
and Hardware system. i.e both mobile and desktop.
The code loads faster in many of the compatible compilers and UI.
Its behaviour is at beyond workload
The ability is above the accepted period
Output running executes faster.
Please find the Program and how this runs for various inputs being passed to
Surname4
computeFactorial():public class Factorial {
public long computeFactorial(int n){
long result = -1;
if (n < 0){
System.out.println("Cannot compute Factorial for Negative Numbers");
}else if (n > 100){
System.out.println("Number is too large to compute Factorial");
}else if (n == 0){
result = 1L;
}else{
result = n * computeFactorial(n - 1);
}
return result;
}
public static void main(String[] args) {
Factorial factorialObj = new Factorial();
Surname5
factorialObj.computeFactorial(-18);
System.out.println(factorialObj.computeFactorial(0));
factorialObj.computeFactorial(110);
System.out.println(factorialObj.computeFactorial(10));
}
}
Surname6
Running head: THE DATA STRUCTURE USING JAVA
Data Structures for Problem Solving(IT265-1802B-01)
Antonio Larkin
The Data Structure Using Java
Instructor: Donald Wilcoxen
6/09/18
1
THE DATA STRUCTURE USING JAVA
2
Abstract
The identification of the different data structures is crucial within the java
programming script. The understanding of the use of queues and stacks, heaps and trees,
the sorting of algorithms increases the speed and efficiency of the usage of data. The proper
and efficient planning of the queues, stacks and heaps allow businesses to be more alert in
their data and in the hyper competitive market place.
THE DATA STRUCTURE USING JAVA
3
Table of Contents
Abstract …………………………………………………………………�...