I need help making J UNIT Test Data for the code below: public class ArrayCheckSchlemme { public
Question:
I need help making J UNIT Test Data for the code below:
public class ArrayCheckSchlemme {
public static void main(String[] args) { int newArray = 5; int arrayMinimum = 1; int arrayMaximum = 100; int elements[] = new int[newArray];
for (int i = 0; i < elements.length; i++) //for loop to add in random #'s between 1-100 elements[i] = (int) (Math.random() * (arrayMaximum - arrayMinimum + 1)) + arrayMinimum;
System.out.print("All Elements: "); for (int i : elements) System.out.print(i + " "); System.out.println();
System.out.print("All Elements Reversed: "); for (int i = elements.length - 1; i >= 0; i--) System.out.print(elements[i] + " "); System.out.println();
System.out.println("First Element: " + elements[0]); System.out.println("Last Element: " + elements[elements.length - 1]);
System.out.print("Odd Indexed Elements: "); for (int i = 1; i < elements.length; i += 2) System.out.print(elements[i] + " "); System.out.println();
System.out.print("Odd Elements: "); for (int i = 0; i < elements.length; i++) //loop to determine odd integers by dividing by 2 if (elements[i] %2 != 0) System.out.print(elements[i] + " "); System.out.println();
System.out.println("Highest Element: " + highestElement(elements)); System.out.println("Lowest Element: " + lowestElement(elements)); }
public static int highestElement(int arrayHighest[]) { //loops to determine the highest and lowest element in the array int highestElement = arrayHighest[0]; for (int i = 1; i < arrayHighest.length; i++) if (arrayHighest[i] > highestElement) highestElement = arrayHighest[i]; return highestElement; }
public static int lowestElement(int arrayLowest[]) { int lowestElement = arrayLowest[0]; for (int i = 1; i < arrayLowest.length; i++) if (arrayLowest[i] < lowestElement) lowestElement = arrayLowest[i]; return lowestElement; } }
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates