Review Arrays
Begin Section 6 Lesson 1: Arrays slides
Complete Section 6 Lesson 1: Arrays programs - ExamAverage, Matrix
Due Today - Hints for the ExamAverage program. - submit the code and a screenshot to canvas.
In a certain class, there are 5 tests worth 100 points each. Write a program that will take in the 5 tests scores for the user, store the tests scores in an array, and then calculate the students average.
Step 1 - Create an int array (refer to ArrayPractice) that will hold 5 values.
Step 2 - Create a for loop that asks the user to enter five exam scores, one at a time.
Each time the user enters a score assign it to the array variable you created in step 1.
So for the first time through the loop it would look something like this myScores[i] = input.nextInt(); where i is the counter in the loop.
Step 3 - Iterate through the array (another for loop) to pull out each value one at a time and add it to a variable called sum.
You need to add the new value to sum so it will look something like this sum = sum + next array value.
Again you will use the counter in your for loop as the index value for the next array value. Refer to the array practice code from Tuesday if you need help using a loop to iterate through an array.
Step 4 - Divide the sum by the number of values to get the average and output the results.
To test your program enter the following scores when the program prompts you:
95, 85, 75, 65, 100 - the average should be 84.
In your for loops for arrays it is best to use the array.length as the condition in your counter instead of a hard coded value like 5. This way if your array is larger your code still works. In the ExamAverage program you would divide the sum not by 5 but by the myScores.length value, that way if you decide to have 10 exam scores your code will still work.
Tomorrow we will look at two dimensional arrays.