A. The following was a problem sequence proposed by Ori Spector that seemed slightly too long to be on a test. Still, the problems are quite good for practice.
B. Write the method prepend(String[] strings, String prefix). It does not alter the input array. Rather, it returns an array containing Strings that works like this:
String[] s = { "boil", "head", "y" }; String[] newStrings = prepend(s, "fish"); // newstrings now contains { "fishboil", "fishhead", "fishy" }
C. Write a class Rectangle that takes four doubles as inputs. The first two numbers are the coordinates of the upper left corner of the Rectangle and the second two numbers are its width and height.
The Rectangle class should have the following methods:
Example:
Rectangle rect = new Rectangle(10, 25, 100, 200); System.out.println(rect.area()); // prints 20000.0 System.out.println(rect.perimeter()); // prints 600.0 System.out.println(rect); // prints { 10.0, 25.0, 100.0, 200.0 }