Assignment #2

Multiple Functions

Due: 2/4/02 at 1:00 pm
 

Write a Java application that provides the following capabilities:
 

  1. Computes the greatest common divisor of  user supplied integers.
  2. Determines whether a user supplied integer is prime.
  3. Determines the nth in a Fibonacci sequence.
  4. Determines the real roots of a quadratic equation (see example below).
General Program requirements:
  1. Java source for all integer functions is contained in a single developer created package.
  2. Java source for each integer function is stored in a separate file.
  3. Upon function completion users are prompted to repeat process or exit.
  4. No more than 80 characters per line printed.
  5. Errant input should be ennunciated.
  6. Java source prologue is extractable using Javadoc utility.
  7. Java source is well commented and extractable using Javadoc.
  8. All Java source and packages are stored in a single zip file for submission.
The program source should be in a file named "Lastname"2.zip. (i.e. Williams2.zip)

The completed assignment should be sent to [email protected]


 Prime Number Determination



Specific Requirements:

 1) Prompt for user input of  an integer.
 2) State whether input integer is prime.

Example Execution

     Integer prime determination:

     Please enter an integer>   36

     36 is not prime.

     Would you like to determine if  another integer is prime (1- Yes, 2 -No)> 2




(For best viewing use Netscape browser)

Quadratic Equation Roots

ax 2 + b x + c = 0,

where a, b and c are fixed coefficients and x is a real number variable.

There are six rules for finding the roots of a quadratic equation:

1.      If   a, b and c areall zero, then every value of x is a real root.

2.       If a and b are zero, but c is nonzero, then there are no real roots.

3.       If a is zero, and b is nonzero then the only real root is x = -c /b.

4.       If a is nonzero and b2 < 4ac, then there are no realroots.

5.       If a is nonzero and b2 = 4ac, then there is one real root x= -b / 2a.

6.      If a is nonzero, and b2 > 4ac, then there are two realroots:








 


Greatest Common Divisor

Specific Requirements:

 1) GCD algorithm must be recursive.
 2) Prompt users for input of 2 integers.
 3) State the GCD of the 2 integers.

Example Execution

     Greatest Common Divisor of  2 integers:

     Please input integer A>   36

     Please input integer b>    20

     The greatest common divisor of 36 and 20 is 4.

     Would you like to compute another GCD (1- Yes, 2 -No)> 2