Java Programming

 

     

 

Friday, March 20th

 

Introduction to Two Dimensional Arrays (Multidimensional Arrays) - arrays within an array

Copy the following code ArrayPractice2 into Codiva and read through the comments so you understand how the code works. At the end of the practice you are asked to create a method called printAnyArray(array)

public static void printAnyArray(int[][] array)
{
fill in the code that goes here - the array you will be printing is called array because that is what it
is named in the parameter. In the sample code the array you printed was called scores.
}

What are the index values of the following array? int[][] myArray = new int[4][3];
Here is what the array would look like at this point:
0 0 0
0 0 0
0 0 0
0 0 0
The index values used to access each cell would be as follows: - remember that index values start with 0
0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
3,0 3,1 3,2
Because you start at 0 3,2 refers to row 4 and column 3
To assign a value of 20 to this index you would do the following myArray[3][2] = 20;


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 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.
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.

If you have finished the Exam Average program and submitted it to canvas move on to the Matrix problem.

 

Homework


 

What

In this lesson, you will learn how to:
•Recognize the correct general form of a class
• Create an object of a class
• Describe object references
• Create methods that compile with no errors
• Return a value from a method
• Use parameters in a method

 

Why

Class templates are the foundation of the Java language. Understanding how to create a class with various methods will be essential to becoming a good Java programmer. Knowing how to instantiate an object and compare it to other objects is critical to learning to use and work with Java data types.

 

How

By completing the slides, quiz and practice exercises.