CSSE 221: Fundamentals of Software Development Honors

Key

Programming assignment (due by Saturday 11:59 pm)

Finish BigRational, as stated in the specification, being sure you have checked in your final, fully-documented copy to the repository.

Written homework to do before week 2 (due before beginning of class on Monday, Sept 10).

As usual, please bring hardcopy for written answers to class to hand in on Monday.
  1. Be sure you've done all reading for this week.
  2. I want to compare two BigRationals, x and y, to see if they are equal value (intuitively, x == y).
    1. Write an expression for this using the compareTo() method. (5 Points)
    2. Write an expression for this using the equals() method. (5 Points)
    3. What is compared if instead I write (x == y)? (Hint, you saw this in section 2.2. This is important to understand!) (10 Points)
  3. For the sake of simplicity, on this question, you may ignore effects such as operating system interrupts that may change the runtime slightly. (Focus on the meaning of big-oh only.)
    1. A block of code is characterized as O(n) and runs in 23 milliseconds. If n is increased by a factor of 8, what is the new runtime of the code? (5 Points)
    2. A block of code is characterized as O(n2) and runs in 400 milliseconds. If n is increased by a factor of 3, what is the new runtime of the code? (5 Points)
  4. What combination of control structure(s) gives code that is O(n3)? (5 Points)
  5. How many times is the sum statement executed (in terms of n):
    for (int i = 0; i < n; i++) {
    
    	for (int j = 0; j < n; j++) {
    		sum++;
    	}
    	for (int j = 0; j < n; j++) {
    		sum++;
    	}
    }
    
    Exact answer = ______, giving an asymptotic answer of O( ______ ). (5 Points Each)
  6. Name at least 3 advantages of unit testing. (5 Points Each)
  7. [Skip this one because I didn't end up covering this in class, but the answer is worth knowing: you should "write a unit test, so the bug won't re-emerge when the code is changed later".] Suppose a user of your program finds a bug. What action should you take beyond fixing the bug?
  8. Write the code for a method that does the following. Note, you may choose to type this into Eclipse to test it, but you aren't required to do so:

    Pass into the method a BigRational object. Evaluate the object to determine if it is equal to its own absolute value. If it is, print the message "Good going", and terminate the program. If it is not, print the message "Not good going", and terminate the program. Regardless of the outcome of this test, print the message "Done" before terminating.

    Write this code twice: once using if-then-else block(s) to evaluate the data and handle a possible error, and once using a try-catch block to evaluate the data and handle a possible error. When using a try-catch block, use a "throw" statement to throw an exception for each case and handle that case within the catch block; you are allowed to use an if statement within the try-catch, but you should not print within the if statement. (20 Points Each)

    Note: This code would never be written using a try-catch block in a production environment; we do it here to make sure you understand important structures.

  9. Reminder that assistants are in Moench F217 from 7-9pm on Sunday through Thursday nights to help you.