Question: Code an interface called CanCalculate. Your interface must contain the following method signature int factorial ( int n ) ; Code a class Calculator that

Code an interface called CanCalculate. Your interface must contain the following method signature
int factorial(int n);
Code a class Calculator that implements the interface. It must use iteration to compute factorial(n)
Code a tester class for class IterativeCalculator, call it IterativeTester. The tester must declare a variable of type CanCalculate and assign it a reference to an object of type IterativeCalculator, and then enter a loop that computes the factorials of the integers ranging between 1 and 10.
CanCalculate myCalc = new IterativeCalculator();
for (int i =2; i <=10; i++) myCalc.factorial(i);
Code a class RecursiveCalculator that implements interface CanCaculate. It must use recursion to compute factorial(n)
Code another tester class, call it RecursiveTester. It must declare a variable of type CanCalculate and assign it a reference to an object of type RecursiveCalculator, and then enter a loop that computes the factorials of the integers ranging between 1 and 10.
CanCalculate myCalc = new RecursiveCalculator();
for (int i =2; i <=10; i++) myCalc.factorial(i);
Rubric
(4 points) Interface CanCalculate:
Has the required method signature.
(4 points) IterativeCalculator class
Implements interface CanCalculate.
Has the required, correct concrete iterative implementation of factorial().
(4 points) RecursiveCalculator class
Implements interface CanCalculate.
Has the required, correct concrete recursive implementation of factorial().
(4 points) IterativeTester class
Has the requires variable declaration, object instantiation and for loop.
(4 points) RecursiveTester class
Has the required variable declaration, object instantiation and for loop

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!