Reference no: EM13941536
It is interesting to watch recursion "in action." Modify the factorial method in Fig. 15.3 to print its local variable and recursive-call parameter. For each recursive call, display the outputs on a separate line, and add a level of indentation. Do your utmost to make the outputs clear, interesting and meaningful. Your goal here is to design and implement an output format that makes it easier to understand recursion. You may want to add such display capabilities to other recursion examples and exercises throughout the text.
// FactorialCalculator.java
// Recursive factorial method.
public class FactorialCalculator
{
// recursive declaration of method factorial
public long factorial( long number )
{
if ( number <= 1 ) // test for base case
return 1; // base cases: 0! = 1 and 1! = 1
else // recursion step
return number * factorial( number - 1 );
} // end method factorial
// output factorials for values 0-10
public void displayFactorials()
{
// calculate the factorials of 0 through 10
for ( int counter = 0; counter <= 10; counter++ )
System.out.printf( "%d! = %dn", counter, factorial( counter ) );
} // end method displayFactorials
} // end class FactorialCalculator
---------------------------------------------------------------------------
// Fig. 15.4: FactorialTest.java
// Testing the recursive factorial method.
public class FactorialTest
{
// calculate factorials of 0-10
public static void main( String args[] )
{
FactorialCalculator factorialCalculator = new FactorialCalculator();
factorialCalculator.displayFactorials();
} // end main
} // end class FactorialTest
----------------------------------------------------------------------
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
Attachment:- FactorialCalculator.zip
Annualized dividend yield-portfolio with a beta
: The S&P 500 Index price is 1492.28 and its annualized dividend yield is 2.30%. LIBOR is .2%. How many futures contracts will you need to hedge a $240 million portfolio with a beta of 1.16 for one year?
|
Summarize your thoughts on microsoft project
: Write a two to three (2-3) page paper in which you summarize your thoughts on Microsoft Project: Give your opinion on how easy or difficult MS Project seems to be from a user experience standpoint
|
What would be the total combined direct labor cost
: What would be the total combined direct labor cost for the two months? A) $122,752.00B) $120,736.00C) $120,881.60D) $122,606.40
|
Feature and parametric analysis
: A comprehensive analysis of existing and similar offerings on the market already including a feature and parametric analysis indicating how your proposal fits into the existing scenario.
|
Modify the factorial method with a recursive call
: You may want to add such display capabilities to other recursion examples and exercises throughout the text.
|
Value of each investment based on requried rate of return
: You have finally saved $10,000 and are ready to make your first investment. You have the three following alternatives for investing that money: Capital Cities ABC, Inc. bonds with a par value of $1,000 and a coupon interest rate of 8.75 percent, are ..
|
Study the demographic profiles of the tourists
: To study the demographic profiles of the tourists such as ages, genders, monthly total income, etc.
|
Decide among several investment alternatives
: Nicole Nelson has come into an inheritance from her grandparents. She is attempting to decide among several investment alternatives. The return after one year is dependent primarily on the interest rate during the next year.
|
Does the criminal justice system have prejudicial overtones
: Measures to avoid injustice and oppression at the hands of the criminal justice system-with or without the use of capital punishment. Does the criminal justice system have prejudicial overtones? How can these be addressed?
|