CIS 1068 - Homework 4

Handed out: 02/09/10, Due: by 10pm on 02/15/10

Your program will consist of a two Java files.
One file, called Server.java, will contain just four public static methods:

	/** Return the greatest common divisor of a and b.
	    We assume that a and b are not 0. 
	*/
	public static int gcd(int a, int b);

	/** Return the largest common proper prime factor of a and b 
	    (i.e. the factor is prime and not equal to a or b)
	*/
	public static int maxFactor(int a, int b);

	/** It prints out the first n Fibonaci numbers, where Fibonaci numbers 
	    are defined by	F(0) = 1, F(1) = 1, F(k+2) = F(k+1)+F(k), for 
	    k = 0, 1, ..
	*/
	public static void fibonaci(int n); 

	/** Given a number a > 1, Returns  a number n such that
	    for some m > 1 we have a = n ^ m.
	    If no such n exists it returns 0,
	*/
	public static int aPower(int a);

	/** Given a number n > 0, prints a sequence, defined as follows
	    if n is 1, print 1
	    if n is 2, print 1,3
	    if n is 3, print 1,3,7
	    if n is 4, print 1,3,7,15
	    and so on
	*/
	public static void printSequence(int n);

The second file, called Client.java will contain just the main method. In this method you will call the methods of the Server class to verify that they work properly. For example you may test gcd and maxFactor with arguments set one time to 48 and 30, another time to -48 and 15, another time to 48 and -21, another time to -48 and -23. You may test aPower by indicating for all numbers from 1 to 100 if they are a power. You may test fibonaci by executing fibonaci(16). You may test printSequence by executing printSequence(8).

You will need to compile both the Server.java file and the Client.java file. Then you can execute the Client file.

Be sure to document your code.

Email your programs to the TA.