import SimpleOutput; /** * Test our amazing and clearly marketable difference computer. Thanks * to our beloved teacher, Sam Rebelsky, for giving us the initiative * to create such a great product. * * Usage: * ji TestDC value1 value2 ... valuen * * @author Carl "Creative Code" Caffeinated * @author Carla "Clearly Clever" Caffeinated * @version 1.0 of October 1999 */ public class TestDC { public static void main(String[] args) { // Prepare for output. SimpleOutput out = new SimpleOutput(); // The array of integers. int[] values = new int[args.length]; // An index into that array; int numValues = 0; // Did the user screw up? Assume not. boolean badInput = false; // Create something that can compute differences. DifferenceComputer computer = new DifferenceComputer(); // Convert each value to an integer. Let the user know if (s)he // screwed up. for (int i = 0; i < args.length; ++i) { try { values[numValues++] = Integer.parseInt(args[i]); } catch (NumberFormatException nfe) { out.println("'" + args[i] + "' is not a number"); badInput = true; } } // for // If the user gave bad input, we need to update the array if (badInput) { int[] tmp = values; values = new int[numValues]; for (int i = 0; i < numValues; i++) { values[i] = tmp[i]; } // for } // if (badInput) // Find the biggest difference out.print("The greatest difference between values is: "); out.println(computer.greatestDifference(values)); // And the least. out.print("The least difference between values is: "); out.println(computer.leastDifference(values)); } // main(String[]) } // class TestDC