Last Revised 6/12/01.

CSC 224 -- Project 2

Part A: String   (50 Points)

Write code to test three of the methods of the String class, other than the charAt and length methods. For help, look at:

  1. The TestString Example in Day1.zip or Day1.txt.
  2. The String description in Appendix M of Lewis and Loftus.
  3. The Summary of Classes for Day1 and Day2 Examples.

Part B: Applet (50 Points)

Write an applet that displays a picture. For help, look at:

  1. The Applet example in Day1.zip.
  2. Section 3.10 in Lewis and Loftus on drawing in applets.
  3. The Summary of Classes for Day1 and Day2 Examples.

Part C: Amicable (100 Points)

Write an application that computes all of the amicable numbers less than or equal to 5000. Look at the Perfect example in Day2.zip.

This project is designed to give you practice using structured programming constructs in Java, in particular the if..else and for constructions. The computations will be done in the main method output will be shown by printing directly to the command line with System.out.println.

Two numbers a and b are amicable if the factors of a sum to b and the factors of b sum to a. Example: The factors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110;   1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 55 + 110 = 284.
The factors of 284 are 1, 2, 4, 71, 142;   1 + 2 + 4 + 71 + 142 = 220.

A simpler problem is finding all the perfect numbers as shown in the Perfect example in the Day2 examples. A number is perfect if its factors sum to itself. The two perfect numbers less than 100 are 6 and 28 because 6 = 1 + 2 + 3 and 28 = 1 + 2 + 4 + 7 + 14.

Modify this program to find all amicable numbers less than 5,000. For each n, you will find the sum (sum1) of its factors. Then find the sum (sum2) of all the factors of sum1. If sum2 = n, you have found a pair of amicable numbers.

Don't print any perfect numbers in your output, and don't print a pair of amicable numbers more than once.

Encorporate any enhancements you can think of to increase the efficiency of your program.