// Hw5.java // , , public class Hw5 { //////////////////////////////////////////////////// /// your methods //////////////////////////////////////////////////// // This method takes a String and an index and returns the integer value // of the digit at the given index.  For example, given "84+23" and // index 0, the method returns the value 8.  If the index is not in bounds // or there is not a digit at that location of the String, the method // should return -1. public static int digitAt(String s, int index) { return 42; } // This method takes four doubles representing the two lines y=m1*x+b1 and // y=m2*x+b2 and returns an int value representing the quadrant where these // two lines intersect, or -1 if they do not intersect in a single point // (either because they are parallel or they are in fact the same line). // Quadrants are numbered normally, so 1 is the top-right, 2 top-left, // 3 bottom-left, and 4 bottom-right. If the two lines intersect at (or // "very nearly" at) the origin, you should return a 0.  If the intersect // directly on the x or y axis, but not at the origin, do something // reasonable (your choice, just be consistent and document your design). public static int quadrantOfIntersection(double m1, double b1, double m2, double b2) { return 42; } // This method takes an integer n and returns true if it is a Fibonacci // number and false otherwise, using the approach described in the // hw5 writeup. public static boolean isFibonacciNumber(int n) { return false; } //////////////////////////////////////////////////// /// test methods for your methods //////////////////////////////////////////////////// public static void testDigitAt() { System.out.print("Testing digitAt... "); assert(digitAt("84+23",-1) == -1); assert(digitAt("84+23", 0) == 8); assert(digitAt("84+23", 1) == 4); assert(digitAt("84+23", 2) == -1); assert(digitAt("84+23", 3) == 2); assert(digitAt("84+23", 4) == 3); assert(digitAt("84+23", 5) == -1); System.out.println("Passed all tests!"); } public static void testQuadrantOfIntersection() { System.out.print("Testing quadrantOfIntersection... "); assert(false); // replace this with your tests!!! System.out.println("Passed all tests!"); } public static void testIsFibonacciNumber() { System.out.print("Testing isFibonacciNumber... "); assert(false); // replace this with your tests!!! System.out.println("Passed all tests!"); } //////////////////////////////////////////////////// /// additional test methods //////////////////////////////////////////////////// public static void checkAssertsAreEnabled() { boolean assertsEnabled = false; try { assert(false); } catch (Throwable t) { assertsEnabled = true; } if (!assertsEnabled) throw new RuntimeException("assert statements not enabled!"); } public static void testAll() { testDigitAt(); testQuadrantOfIntersection(); testIsFibonacciNumber(); } //////////////////////////////////////////////////// /// main method //////////////////////////////////////////////////// public static void main(String[] args) { checkAssertsAreEnabled(); testAll(); } }