Allan Didier

Computer Science Teacher

# Array Intro

## Goals

Students will demonstrate their ability to use arrays in a Java program.

• Arrays
• For loops

## Program Details

Write a program that will find the sum, average, high, and low numbers in an array of twenty integers, as well as report a frequency distribution of the numbers (see below).

• You can do this all in one main program. You don’t need to use your MyMath Methods or a separate class.
• Initialize your array in the following two ways. You can only have one way active at a time, so comment the other out when running the program.
• With twenty set numbers: like 0, 200 and eighteen 100s. You can use this to test the rest of your code to make sure the rest of the code works because you know what this array should return.
• With 20 random integers ranging from 0 to 999 inclusive. Once you know your code works, test it with random numbers.
• The sum, average, high, and low algorithms can be straight in your main program, or separate methods.
• Frequency Distribution. Report how many numbers fall within the following ranges:
• 0-99
• 100-199
• 200-299
• and so on to 900 to 999.
• Print the following
• All of the numbers in the array
• The sum of the numbers in the array
• The average of the numbers in the array
• The high number in the array
• The low number in the array
• The frequency distribution of the numbers in the array

Testing:

• Initially run the code with only the array being initialized directly, not randomly. This will make testing the rest of your code easier. When the rest of the code works (or you think it does), then comment out this code. Un-comment (or write) the random initialization of the array and test your code with random numbers.

Hints:

• We have not discussed passing arrays in as method parameters, yet. So, modifying  your MyMathMethods may be tricky. You can do this, but it is not required.

## Resources

### Java Textbook

Chapter 8: Arrays