// Program to test solutions to problem #6 on the cse142 midterm, winter 2012. // Fill in your solution to hasMidpoint, then compile and run the program. import java.util.*; public class Test6 { public static boolean hasMidpoint(int x, int y, int z) { // fill in your solution here // you can also rename the parameters above } // this is the sample solution public static boolean hasMidpoint2(int x, int y, int z) { return (2 * x == y + z || 2 * y == x + z || 2 * z == x + y); } public static void main(String[] args) { test(10, 12, 14); test(14, 10, 12); test(12, 10, 14); test(2, 10, 6); test(8, 8, 8); test(25, 10, -5); test(2, 3, 4); test(2, 3, 5); test(3, 1, 3); test(2, 4, 5); test(21, 9, 58); test(2, 8, 16); } public static void test(int x, int y, int z) { System.out.println("testing " + x + ", " + y + ", " + z); boolean result1 = false; boolean fail = false; try { result1 = hasMidpoint(x, y, z); if (result1 != hasMidpoint(x, z, y) || result1 != hasMidpoint(y, x, z) || result1 != hasMidpoint(y, z, x) || result1 != hasMidpoint(z, x, y) || result1 != hasMidpoint(z, y, x)) { System.out.println("fails with different parameter order"); fail = true; } } catch (RuntimeException e) { System.out.println("threw " + e); fail = true; } boolean result2 = hasMidpoint2(x, y, z); System.out.println("correct = " + result2 + ", theirs = " + result1); if (!fail && result1 == result2) { System.out.println("PASS"); } else { System.out.println("FAIL"); } System.out.println(); } }