15-110 Sections G-J / Spring 2010 / Quiz 5
3 Questions / 15 Minutes

  1. Write a method named reverse that takes an array of ints and non-destructively returns a new array of those same values in reverse.
     

  2. Write a method named removeEvens that takes an array of ints and non-destructively returns a new array with the even values removed and the odd values in their original order (so { 1, 2, 7, 4, 3, 5 } --> { 1, 7, 3, 5 }.
     

  3. Write a class named Complex that models a complex number.  In particular, write a constructor, a toString, and a times method.
    Hint #1:  A complex number (a+bi) can be defined with two doubles, a (the "real" part) and b (the "imaginary" part).
    Hint #2:  (a+bi) * (c+di) = (ac-bd) + (ad+bc)i