Java Programming

 

     

 

Wednesday, March 25th

 

Need Help? Email me at cdodge@seq.org with any questions or problems that you have.

Review of Multidimensional Arrays

Step 3. Create a printArray( ) method that accepts any 2D array of integers and prints out the array for the user. Remember that you declare methods outside of your main method so find the end of your main method } and then write your method after the closing } of the main method.
Here is the start of the code, you will need to fill in everything between the { }

public static void printArray(int[][] array) {

You will need a for loop that iterates through the 2D array, refer to the example in ArrayPractice2.
Just a hint here, in the outer loop you will use just use println() to force a line return.
In the inner loop you will use print( ) to print each array value and a space. Since the parameter that you are passing to this method is array this is the array you will print.

}

Test your method by calling it in your main method and using array1 as the parameter
printArray(array1);
Since you have not provided any values to array1 the output should look like this:

0 0
0 0

Run your code in Codiva. Copy the code and then take a screen shot of the output. Submit to Canvas for Matrix2 Print Array.

In the main method you would call the following method with this line:
printArray(array1);
You will want to call this method in each of your switch statements, the only thing that will change is the parameter. For option 2 you would want to use this code: printArray(array2);
For options 3, 4, & 5 you would want to : printArray(array3); since array3 will store the answer from the calculations performed in option 3, 4 &5.

 

8. In Algebra class we learn about matrices. We learn to add, subtract, and multiply 2x2 matrices.

Write a program that take in two matrices and then allow the user to choose to add, subtract, or multiply them and display the answer. The program will display the following menu:
A. Enter Matrix A - display the Matrix so the output look like the actual matrix, not just a list of numbers.
B. Enter Matrix B - display the Matrix so the output look like the actual matrix, not just a list of numbers.
C. Display A + B - display the output so it is in the form of the actual matrix answer, not just a list of numbers.
D. Display A - B
E. Display A * B
F. Exit

The program should loop and allow the user to continue to choose different options until they choose quit. The well written program will modularize the process into different methods.
Suggested methods:
printArray(int [][] array)
fillArray(Scanner input, int[][] array)
addArray(int[][]array1, int[][]array2, int[][] answerArray)
subtractArray(int[][]array1, int[][]array2, int[][] answerArray)
multiplyArray(int[][]array1, int[][]array2, int[][] answerArray)

Tomorrow you will start to fill your arrays.


 

Homework

Install Eclipse on your home computer if you would like to be able to work on your java at home.

 

What

Objectives for Section 4 Lesson 2
In this lesson, you will learn how to:
• Describe the general form of a Java program
• Use variables and apply the IF and FOR statements
• Create a block of code
• Recognize Java keywords

 

Why

Eclipse is an efficient and easy to use a development environment for creating Java programs. It is a well known tool by many Java programmers and is used in many development environments.
Learning Eclipse in this lesson will give you additional skills with tools used in the Java programming space.

 

How

By completing the slides, quiz and practice exercises.