Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment7 – MathStudent II CS1405 Spring2011 Description: Modify the class Mat

ID: 3623762 • Letter: A

Question

Assignment7 – MathStudent II    CS1405  Spring2011

Description:
Modify the class MathStudent you created in Assignment6 by adding two methods:
calculateFactorial and findFibonacciNumbers.
Modify the class MathStudentTest as described below to test the new methods

Make sure you have a correct MathStudent class to start out with.
If you have any doubts use the sample MathStudent class I included

Updated UML class diatram:

-firstName: String

-lastName: String

-gpa: double

<<constructor>>MathStudent(fName: String, lName: String, gapVaule:Double)

+getGpa():Double

+setGpa(gpaValue: double)

+counterBySeven(max:int)

+calculateFactorial(number:int):int

+findFibonacciNumbers(count:int)

+toString(): String

Ad calculateFactorial:
The method calculateFactorial has a parameter called number of type integer. It returns the factorial of number.

The factorial of 3 denoted by 3! is 3 * 2 * 1.
The factorial of 5 denoted by 5! is 5 * 4 * 3 * 2 * 1
In general: the factorial of n denoted by n! is n * (n – 1) * … * 1

You may assume that a positive number is passed as an argument.

Ad findFibonacciNumbers:
The method findFibonacciNumbers has a parameter called count which tells you how many Fibonacci numbers you should find and display.
Assume that any positive number can be passed as an argument (incl. 1 or 2 )
Here are the rules for Fibonacci numbers:

—  F0 = 0 and F1 = 1

—  Fn = Fn-1 + Fn-2

That means that the first Fibonacci number is 0. The second one is 1.  The third Fibonacci number is the first + the second. The fourth is the second + the third. The fifth is the third + the fourth, etc.

Example:  the first 7 Fibonacci numbers:
 
first Fibonacci number: 0           //  per definition
Second Fibonacci number: 1     //  per definition
 third Fibonacci number: 1        //  0 + 1
 forth Fibonacci number: 2        //  1 + 1
fifth Fibonacci number: 3          //  1 + 2
sixth Fibonacci number: 5         //   2 + 3
seventh Fibonacci number: 8   //   3 + 5

FYI:
A tiling with squares whose sides are successive Fibonacci numbers in length and
A Fibonacci spiral created by drawing arcs connecting the opposite corners of squares in the Fibonacci tiling

  

This assignment does not require you to gather input from the user. This time we don’t test the set accessor  any more. We did that already and we know that it works.
This time I want to test and show off the capabilities of the math student.

Sample output:

Updated MathStudent Test:
-------------------------
Emily Johnson .. gpa:3.7

Counting by 7: 7 14 21 28 35 42 49 56 63 70 77
First 15 Fibonacci numbers: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
7! = 5040

Explanation / Answer

//calculateFactorial

public class Fact

{

for(int counter = 0; counter <=15;counter++)

System.out.printf("%d! = %d ",counter,calculateFactorial(counter));

}

public long calculateFactorial(long number)

{

if(nunmber <=1)

return 1;

else

return number * factorial (number -1);

}

//findFibonacciNumbers

public class Fib

{

System.out.println("The First 15 numbers in the fibonacci series are:");

for(int i=0;i<15;i++)

System.out.print( findFibonacciNumbers(i)+" ");

}

public static int findFibonacciNumbers(int n)

{

if(n==0)

return 0;

else if(n==1)

return 1;

else

return fib(n-1)+fib(n-2);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote