Make a program arraycheck. Using a for loop and Math.random, initialize an array with five random integers
Fantastic news! We've Found the answer you've been seeking!
Question:
Make a program arraycheck. Using a for loop and Math.random, initialize an array with five random integers between 1 and 100. Then, print these eight lines of output:
- Every element in the array
- All elements in reverse order
- First element
- Last element
- Every element at an odd index
- Every odd element
- Highest element
- Lowest element
I also have guidelines for the code:
- Your program should not use magic numbers in your for loops. This means that you should use your arrayName.length to find out what the last element is. In your code, the only 5 that should be present is on the first array declaration. I should easily be able to modify your array declaration to be 11 or 12 or 32 and your program should still function.
- Create and use variables in your Math.random statement. It should not be: int randNum = 1 + (int) (Math.random() * 100);
- As a reminder: If the remainder when you divide by 2 is 0, it's even. % is the operator to get a remainder.
- Use an enhanced for loop to print every element in the array (Item #1 above).
- Create two methods - one for determine the highest element and one for determining the lowest element. Pass the array as the parameter - do not make a global array. Just remember to print in the main method only!
- I need to make a JUNIT tester file to test the two methods you have created.
Ending with creating Junit test data to test the two methods created.
Related Book For
Applied Statistics In Business And Economics
ISBN: 9780073521480
4th Edition
Authors: David Doane, Lori Seward
Posted Date: