Instructions

The day after these are assigned we will cover solutions in class. After that, I will post the solutions online.

Assignments

  1. Extending Contact & AddressBook Classes What good is an AddressBook if it can't store addresses? You are to extend the example classes of Contact and AddressBook (covered in class) to allow the storage of addresses. The interface should also be updated to include an input appropriate for entering an address.

    Specifically, do the following:
    1. Create a new project in Eclipse called "NewAddressBook"
    2. Add a new Java class to your project called "NewAddressBook"
    3. Copy the "TestAddressBook.java" file from the website into that file.
    4. Modify it to the following: Add a label and input for entering the address.
    5. Modify the Contact class to include an address property, of an appropriate type.
    6. When the user fills out the form to enter a new contact (include name, email, beard length, and now address), and click "Add Contact", be sure to set the address property of the Contact object and have the display also include the address of all contacts.
    Install Java plugin to view this applet.



  2. Using a method for the Powers Assignment Recall from the first assignment that you had to write a program to compute baseexponent for a user provided base and exponent.

    What you must now do is re-write that assignment, only you will defined a method to compute the power.

    Specifically, do the following:
    1. Create a new project in Eclipse called "PowersWithAMethod"
    2. Add a new Java class "PowersWithAMethod"
    3. Copy the code from your old Powers assignment into this one.
    4. Add a method to your file with the following definiton:
                     int  power( int base, int exponent ) {
                           ...
                     }
    5. Put all of your code to compute the power into that method.
    6. Now, use this method in your actionPerformed method to compute and display the power.
    7. Your new applet should look and work identically to your old one
    Install Java plugin to view this applet.



  3. A Big One: Recursion! The Fibonacci numbers are a sequence of integers where the 1st and 2nd numbers in sequence are both 1 and each of the remaining numbers in the sequence is the sum of the previous two. Expressed mathematically this is:
          ƒ(1) = 1
          ƒ(2) = 1
          ƒ(i) = ƒ(i-1) + ƒ(i-2)
          
    Write a program to find the nth Fibonacci number.

    Specifically, you should:
    1. Create a new project in Eclipse called "Fibonacci"
    2. Create a new Java class called "Fibonacci"
    3. Use the sample code from the Generic program we covered yesterday.
    4. Modify it to the following: Change the label to say "N: ".
    5. Modify the button to say "Compute Nth Fibonnaci Number"
    6. Add a method to your class with the following method...
                     int fibonacci(int n) {
      
                           // here's where you have to add some code!
                           // specifically, you want to return the nth Fibonacci number
      
                     }
    7. When the user clicks the button, display the following in the output/textarea:
      "The Xth Fibonacci number is Y"
      where X is the number the user entered and Y is the Xth Fibonacci number.
    Install Java plugin to view this applet.