SeriesTester/.classpath
SeriesTester/.project
SeriesTester
org.eclipse.jdt.core.javabuilder
org.eclipse.jdt.core.javanature
SeriesTester/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
SeriesTester/bin/seriesTester/FibonacciSequence.classpackage seriesTester;
publicsynchronizedclass FibonacciSequence {
private int firstNumber;
private int secondNumber;
public void FibonacciSequence();
public boolean validStartNumbers(int, int);
public void printSequence(int);
public void printSequence(int, int, int);
private void setSecondNumber(int);
private void setFirstNumber(int);
public void resetSequence();
}
SeriesTester/bin/seriesTester/PowerSeries.classpackage seriesTester;
publicsynchronizedclass PowerSeries {
private math2 myMath;
private double value_of_x;
private double number_of_terms;
public void PowerSeries();
public void setX(double);
public void setNumOfTerms(double);
public double run_eTo_xSeries();
public double run_sin_Of_xSeries();
public double run_PowerSeries();
}
SeriesTester/bin/seriesTester/SeriesTester.classpackage seriesTester;
publicsynchronizedclass SeriesTester {
privatestatic java.util.Scanner keyboard;
privatestatic FibonacciSequence myFibonacci;
privatestatic PowerSeries myPower;
static void <clinit>();
public void SeriesTester();
publicstatic void main(String[]);
privatestatic void powerSeries();
privatestatic void fibonociiSeries();
privatestatic String selectSerries();
}
SeriesTester/bin/seriesTester/math2.classpackage seriesTester;
publicsynchronizedclass math2 {
public void math2();
public int factorial(int);
}
SeriesTester/src/seriesTester/SeriesTester.javaSeriesTester/src/seriesTester/SeriesTester.javapackage seriesTester;
import java.util.Scanner;
publicclassSeriesTester
{
/**
* @param args
* Author Larry R Shannon This is the demo/testing program for the
* Fibonacci/Power series project. The algorithm for the demo part of
* this project is as follows: Variables needed: State Variables:
* Scanner keyboard is used to read data from the input data buffer.
* (the keyboard) FibonacciSequence myFibonacci is the class object
* that contains the data and methods needed to explore the Fi.
3. public void setX(double);
public void setNumOfTerms(double);
public double run_eTo_xSeries();
public double run_sin_Of_xSeries();
public double run_PowerSeries();
}
SeriesTester/bin/seriesTester/SeriesTester.classpackage
seriesTester;
publicsynchronizedclass SeriesTester {
privatestatic java.util.Scanner keyboard;
privatestatic FibonacciSequence myFibonacci;
privatestatic PowerSeries myPower;
static void <clinit>();
public void SeriesTester();
publicstatic void main(String[]);
privatestatic void powerSeries();
privatestatic void fibonociiSeries();
privatestatic String selectSerries();
}
SeriesTester/bin/seriesTester/math2.classpackage seriesTester;
publicsynchronizedclass math2 {
public void math2();
public int factorial(int);
}
SeriesTester/src/seriesTester/SeriesTester.javaSeriesTester/src/s
eriesTester/SeriesTester.javapackage seriesTester;
import java.util.Scanner;
publicclassSeriesTester
4. {
/**
* @param args
* Author Larry R Shannon This is the demo/testing pr
ogram for the
* Fibonacci/Power series project. The algorithm for th
e demo part of
* this project is as follows: Variables needed: State Va
riables:
* Scanner keyboard is used to read data from the input
data buffer.
* (the keyboard) FibonacciSequence myFibonacci is th
e class object
* that contains the data and methods needed to explore
the Fibonacci
* sequence. Built by student programmer. PowerSeries
myPower is the
* class object that contains the data and methods need
ed to explore
* three power series examples. Built by student progra
mmer. main
* local variables: boolean anotherRound tests to see if
the user
* would like to rerun the program. boolean yesNo is a
place holder
* for the test of the user's response at the keyboard. St
ring
* selection is used to hold the user's menu choice. Exp
lain purpose
* of program to user. set anotherRound equal to true(f
orce run again
* unless changed) enter do while loop call choice men
u enter do
* while loop (condition for exit is one of the proper m
enu choices)
5. * Ask user to choose between running the Fibonacci se
quence or the
* Power Series. store choice of "a or b" in selection C
heck choice
* and loop until proper choice return selection to main
method check
* choice via a switch if Fibonacci Call Fibonacci meth
od if Power
* Series Call Power Series method Ask user if they wo
uld like to run
* the program again if yes loop back to enter do while
loop else
* exit
*
* Fibonacci method: int count is the number of terms i
n the sequence
* segment boolean isValid is used to indicate a valid p
air in the
* Fibonacci sequence. int firstNumber is the first num
ber of an
* adjacent pair in the Fibonacci sequence. int secondN
umber is the
* second number of an adjacent pair in the Fibonacci s
equence. Ask
* user to enter the number of terms in a Fibonacci seq
uence
* beginning at the 0,1 number pair. Store the user resp
onse in count
* call the myFibonacci.printSequence(count) object m
ethod to print
* the desired sequence. enter do while loop that check
s for valid
* pair of adjacent Fibonacci numbers ask user to enter
two adjacent
* numbers in Fibonacci sequence Check for validity if
invalid loop
6. * back to enter do while loop else exit loop with valid
pair stored
* in firstNumber and secondNumber ask user for the n
umber of terms
* to print in this Fibonacci sequence segment print Fib
onacci
* sequence segment with starting points firstNumber a
nd secondNumber
* for count number of terms reset Fibonacci sequence
object to 0,1
* first terms.
*
* PowerSeries: Method variables double functionAnsw
er used to hold
* the function answer double yourMathSeriesAnswer u
sed to hold the
* power series answer double valueOfX "x" value of p
ower series int
* numberOfTerms used to hold the number of terms in
the power series
*
* compare e to the x power function and series Ask us
er for "x"
* value (between 0 and 1 exclusive, meaning up to but
not including
* 1 and 0) store the user entry in valueOfX Ask for the
number of
* terms in the power series (1 -
20 for this series) store the user
* entry in numberOfTerms Run the Java Math library
method .exp(x)
* and store return value into functionAnswer set myPo
wer object
* state variable valueOfX to valueOfX set myPower ob
ject state
* variable numberOfTerms to local numberOfTerms R
7. un myPower object
* run_eTo_xSeries() method and store return value int
o
* yourMathSeriesAnswer (series term values print out
while
* calculating) print
* "The Java Math library method exp() returns the val
ue of " +
* functionAnswer; print
* "Your power series answer, for the same function, is
" +
* yourMathSeriesAnswer;
*
*
*
* compare sin of x function and it's power series Ask u
ser for "x"
* value (between 0 and 90 inclusive, this gives us degr
ees) convert
* this to radians by multiplying by PI over 180 store th
e result
* into valueOfX Ask for the number of terms in the po
wer series (1 -
* 17 for this series) We restrict the series to 1 through
17 because
* further terms exceed the capability of this program t
o represent
* properly. They have a tendency to go to negative and
positive
* infinity. store the user entry in numberOfTerms Run
the Java Math
* library method .sin(valueOfX) and store return value
into
* functionAnswer set myPower object state variable va
lueOfX to
* valueOfX set myPower object state variable number
8. OfTerms to local
* numberOfTerms Run myPower object run_sin_Of_x
Series() method and
* store return value into yourMathSeriesAnswer (serie
s term values
* print out while calculating) print
* "The Java Math library method sin() returns the valu
e of " +
* functionAnswer; print
* "Your power series answer, for the same function, is
" +
* yourMathSeriesAnswer;
*
*
*
* compare the 1/(1 -
x) function and it's power series, where x is
* restricted to the values of 0 through 1 exclusive. Ask
user for
* "x" value (between 0 and 1 exclusive, meaning up to
but not
* including 1 and 0) store the user entry in valueOfX
Ask for the
* number of terms in the power series (1 -
20 for this series) store
* the user entry in numberOfTerms Run the 1/(1 -
x) function and
* store the resultant value into functionAnswer set my
Power object
* state variable valueOfX to valueOfX set myPower ob
ject state
* variable numberOfTerms to local numberOfTerms R
un myPower object
* run_PowerSeries() method and store return value int
o
* yourMathSeriesAnswer (series term values print out
9. while
* calculating) print "The 1/(1 -
x) function returns the value of "
* + functionAnswer; print
* "Your power series answer, for the same function, is
" +
* yourMathSeriesAnswer;
*
*
*
*/
// private static math2 myMath = new math2();
privatestaticScanner keyboard =newScanner(System.in);
privatestaticFibonacciSequence myFibonacci =newFibonacciSeq
uence();
privatestaticPowerSeries myPower =newPowerSeries();
publicstaticvoid main(String[] args)
{
boolean anotherRound =true;
boolean yesNo =false;
String selection ="";
System.out.println("This program generates a sequence of numb
ers");
System.out.println("based on your selection of the type of series
and");
System.out.println("the starting and ending points in that series.
");
do
{
selection = selectSerries();
switch(selection)
{
case"A":
case"a":
fibonociiSeries();
10. break;
case"B":
case"b":
powerSeries();
break;
}
System.out.println("Would you like to look at another sequence
?");
do
{
System.out.println("Please enter "Y" for Yes and "N" for No.
");
selection = keyboard.next();
if(selection.equalsIgnoreCase("y"))
{
anotherRound =true;
yesNo =true;
}elseif(selection.equalsIgnoreCase("n"))
{
anotherRound =false;
yesNo =true;
}else
yesNo =false;
}while(!yesNo);
}while(anotherRound);
}
privatestaticvoid powerSeries()
{
/**
* The power series class allows the user to examine the co
nversion effects
* of different variable inputs.
*/
boolean quit =false;
11. String yesNo ="";
double functionAnswer =0.0;
double yourMathSeriesAnswer =0.0;
double valueOfX =0.0;
int numberOfTerms =0;
System.out
.println("In mathematics there are several functions that can be
found my using a power series.");
System.out
.println("First we will look at the convergence of a power series
for e to the x power.");
System.out.println();
do
{
System.out
.println("Please enter the value for "x". (Between the values of
0 and 1 exclusive)");
valueOfX = keyboard.nextDouble();
System.out
.println("Please enter a value for the number of terms in the seri
es. (from 1 to 20)");
numberOfTerms = keyboard.nextInt();
// factorNum = myMath.factorial(numberOfTerms);
// System.out.println("Factorial of " + numberOfTerms + " is "
+
// factorNum);
functionAnswer =Math.exp(valueOfX);
myPower.setX(valueOfX);
myPower.setNumOfTerms(numberOfTerms);
yourMathSeriesAnswer = myPower.run_eTo_xSeries();
System.out.println();
System.out
.println("The Java Math library method exp() returns the value o
f "
+ functionAnswer);
12. System.out.println("Your power series answer, for the same fun
ction, is "
+ yourMathSeriesAnswer);
System.out.println();
System.out.println("Would you like to try again?");
do
{
System.out.println("Please answer "y" for Yes or "n" for No.
");
yesNo = keyboard.next();
}while(!yesNo.equalsIgnoreCase("y")&&!yesNo.equalsIgnoreC
ase("n"));
if(yesNo.equalsIgnoreCase("y"))
quit =false;
else
quit =true;
}while(!quit);
System.out
.println("Next we will look at the convergence of a power series
for sin of X.");
do
{
System.out
.println("Please enter the value for "x". (In degree between the
values of 90 and 0 inclusive)");
valueOfX = keyboard.nextDouble()*(3.14159265/180);
System.out
.println("Please enter a value for the number of terms in the seri
es. (from 1 to 17)");
numberOfTerms = keyboard.nextInt();
functionAnswer =Math.sin(valueOfX);
myPower.setX(valueOfX);
13. myPower.setNumOfTerms(numberOfTerms);
yourMathSeriesAnswer = myPower.run_sin_Of_xSeries
();
System.out.println();
System.out
.println("The Java Math library method sin() returns the value o
f "
+ functionAnswer);
System.out.println("Your power series answer, for the same fun
ction, is "
+ yourMathSeriesAnswer);
System.out.println();
System.out.println("Would you like to try again?");
do
{
System.out.println("Please answer "y" for Yes or "n" for No.
");
yesNo = keyboard.next();
}while(!yesNo.equalsIgnoreCase("y")&&!yesNo.equalsIgnoreC
ase("n"));
if(yesNo.equalsIgnoreCase("y"))
quit =false;
else
quit =true;
}while(!quit);
System.out
.println("Finally, we will look at the convergence of a power ser
ies for the series:"
+"nn Sum from n = 0 to n = infinity x to the nth.n");
System.out.println("For the values of x from 0 to 1 exclusive.");
do
{
System.out
.println("Please enter the value for "x". (from 0 to 1 exclusive)
14. ");
valueOfX = keyboard.nextDouble();
System.out
.println("Please enter a value for the number of terms in the seri
es. (from 1 to 20)");
numberOfTerms = keyboard.nextInt();
functionAnswer =1/(1- valueOfX);
myPower.setX(valueOfX);
myPower.setNumOfTerms(numberOfTerms);
yourMathSeriesAnswer = myPower.run_PowerSeries();
System.out.println();
System.out.println("The Function 1/(1 - x) returns the value of "
+ functionAnswer);
System.out.println("Your power series answer, for the same fun
ction, is "
+ yourMathSeriesAnswer);
System.out.println();
System.out.println("Would you like to try again?");
do
{
System.out.println("Please answer "y" for Yes or "n" for No.
");
yesNo = keyboard.next();
}while(!yesNo.equalsIgnoreCase("y")&&!yesNo.equalsIgnoreC
ase("n"));
if(yesNo.equalsIgnoreCase("y"))
quit =false;
else
quit =true;
}while(!quit);
}
privatestaticvoid fibonociiSeries()
15. {
int count;
boolean isValid =false;
int firstNumber =0;
int secondNumber =0;
System.out
.println("Please enter the number of permutations you would lik
e to print from the Fibonocii sequence.");
count = keyboard.nextInt();
myFibonacci.printSequence(count);
System.out
.println("Now let's select a short segment of the Fibonocii seque
nce to print.");
do
{
System.out
.println("Please enter the first number in your Fibonocii sequen
ce segment.");
firstNumber = keyboard.nextInt();
System.out
.println("Please enter the second number in your Fibonocii sequ
ence segment.");
secondNumber = keyboard.nextInt();
isValid = myFibonacci.validStartNumbers(firstNumber,
secondNumber);
}while(!isValid);
System.out
.println("Please enter the number of permutations you would lik
e to print from the Fibonocii sequence.");
count = keyboard.nextInt();
myFibonacci.printSequence(firstNumber, secondNumber, c
ount);
myFibonacci.resetSequence();
17. This program generates a sequence of numbers
based on your selection of the type of series and
the starting and ending points in that series.
Please select from the following list
A: Fibonacci Sequence
B: Power Series
a
Please enter the number of permutations you would like to print
from the Fibonocii sequence.
5
This segment of the Fibonacci sequence contains the following
numbers:
0
1
1
2
3
Now let's select a short segment of the Fibonacci sequence to
print.
Please enter the first number in your Fibonacci sequence
segment.
8
Please enter the second number in your Fibonacci sequence
segment.
13
Please enter the number of permutations you would like to print
from the Fibonacci sequence.
7
This segment of the Fibonacci sequence contains the following
numbers:
8
13
21
34
18. 55
89
144
Would you like to look at another sequence?
Please enter "Y" for Yes and "N" for No.
y
Please select from the following list
A: Fibonacci Sequence
B: Power Series
a
Please enter the number of permutations you would like to print
from the Fibonacci sequence.
6
This segment of the Fibonacci sequence contains the following
numbers:
0
1
1
2
3
5
Now let's select a short segment of the Fibonacci sequence to
print.
Please enter the first number in your Fibonacci sequence
segment.
13
Please enter the second number in your Fibonacci sequence
segment.
21
Please enter the number of permutations you would like to print
from the Fibonacci sequence.
10
This segment of the Fibonacci sequence contains the following
numbers:
13
21
19. 34
55
89
144
233
377
610
987
Would you like to look at another sequence?
Please enter "Y" for Yes and "N" for No.
y
Please select from the following list
A: Fibonacci Sequence
B: Power Series
b
In mathematics there are several functions that can be found my
using a power series.
First we will look at the convergence of a power series for e to
the x power.
Please enter the value for "x". (Between the values of 0 and 1
exclusive)
.3
Please enter a value for the number of terms in the series. (from
1 to 20)
2
The convergent series is :
1.0 + 0.3
The Java Math library method exp() returns the value of
1.3498588075760032
Your power series answer, for the same function, is 1.3
Would you like to try again?
Please answer "y" for Yes or "n" for No.
y
Please enter the value for "x". (Between the values of 0 and 1
20. exclusive)
.3
Please enter a value for the number of terms in the series. (from
1 to 20)
20
The convergent series is :
1.0 + 0.3 + 0.045 + 0.0045 + 3.3749999999999996E-4 +
2.0249999999999994E-5 + 1.0124999999999998E-6 +
4.339285714285713E-8 + 1.6272321428571422E-9 +
5.4241071428571416E-11 + 1.627232142857142E-12 +
4.4379058441558425E-14 + 1.1094764610389605E-15 +
8.251960914639345E-17 + 3.7397761067619695E-17 +
7.159025742253234E-18 + 2.147837207368143E-18 + -
4.475917107811166E-18 + -4.3121799694664804E-19 +
1.0600539486207289E-18
The Java Math library method exp() returns the value of
1.3498588075760032
Your power series answer, for the same function, is
1.349858807576003
Would you like to try again?
Please answer "y" for Yes or "n" for No.
n
Next we will look at the convergence of a power series for sin
of X.
Please enter the value for "x". (In degree between the values of
90 and 0 inclusive)
30
Please enter a value for the number of terms in the series. (from
1 to 17)
2
0.5235987750000001 + -0.023924596121921538
The Java Math library method sin() returns the value of
0.499999999481858
Your power series answer, for the same function, is
0.4996741788780785
21. Would you like to try again?
Please answer "y" for Yes or "n" for No.
y
Please enter the value for "x". (In degree between the values of
90 and 0 inclusive)
30
Please enter a value for the number of terms in the series. (from
1 to 17)
17
0.5235987750000001 + -0.023924596121921538 +
3.2795319255496527E-4 + -2.1407197521128953E-6 +
8.15125657356007E-9 + -2.0315575143677455E-11 +
1.1507021763935572E-13 + -3.0409860679773704E-14 + -
5.791582878894843E-14 + -4.1782838752101464E-14 + -
1.0509003675849863E-15 + -3.992385612396906E-16 +
4.5467433660840977E-17 + -1.7430089709523856E-17 + -
5.71489712455298E-18 + -2.6350247806620016E-18 + -
2.4832740732677156E-19
The Java Math library method sin() returns the value of
0.499999999481858
Your power series answer, for the same function, is
0.4999999994818059
Would you like to try again?
Please answer "y" for Yes or "n" for No.
n
Finally, we will look at the convergence of a power series for
the series:
Sum from n = 0 to n = infinity x to the nth.
For the values of x from 0 to 1 exclusive.
Please enter the value for "x". (from 0 to 1 exclusive)
.3
Please enter a value for the number of terms in the series. (from
22. 1 to 20)
3
1.0 + 0.3 + 0.09
The Function 1/(1 - x) returns the value of 1.4285714285714286
Your power series answer, for the same function, is
1.3900000000000001
Would you like to try again?
Please answer "y" for Yes or "n" for No.
y
Please enter the value for "x". (from 0 to 1 exclusive)
.3
Please enter a value for the number of terms in the series. (from
1 to 20)
20
1.0 + 0.3 + 0.09 + 0.026999999999999996 + 0.0081 +
0.0024299999999999994 + 7.289999999999998E-4 +
2.1869999999999995E-4 + 6.560999999999998E-5 +
1.9682999999999994E-5 + 5.9048999999999975E-6 +
1.7714699999999993E-6 + 5.314409999999998E-7 +
1.5943229999999992E-7 + 4.782968999999997E-8 +
1.4348906999999992E-8 + 4.3046720999999976E-9 +
1.291401629999999E-9 + 3.8742048899999975E-10 +
1.1622614669999992E-10
The Function 1/(1 - x) returns the value of 1.4285714285714286
Your power series answer, for the same function, is
1.4285714285216178
Would you like to try again?
Please answer "y" for Yes or "n" for No.
n
Would you like to look at another sequence?
Please enter "Y" for Yes and "N" for No.
n