Introduction to Java using NetBeans Section 8 : 2-D Arrays (a Matrix) and Creating your own Methods |
You can use Java to create a two-dimensional array by creating an array within an array. The elements in two-dimensional arrays can be thought of as being organized into rows and columns. The rows are the first dimension of the array and the columns the second. |
2D Array Tutorial - Numbers // Adding elements to the array the long way int [][] intNumbersArray = new int [5] [4];
// Printing the Array // Getting Input from the User Your Turn
Display a row entered by the user Display a col entered by the user Calcualte the sum of all elements in the array Calculate the sum of each row and each col and display as shown below
|
8.1 - intGradeArrays(Console) Create a intGradeArrays program that has 5 sutdents and 5 marks for each student Use the following: - a 1D strStudentArray - a 2D intGradeArrays - a 1D intStudentAverageArray - a 1D inMarkAverageArray
Sample Data // strStudentArray Names // Marks for Student 0 intGradeArray [0][0]=94; // Marks for Student 1 intGradeArray [1][0]=32; // Marks for Student 2 intGradeArray [2][0]=94; // Marks for Student 3 intGradeArray [3][0]=34; // Marks for Student 4 intGradeArray [4][0]=94;
Use a nested for loop to calculate the test average for each student. Use a nested for loop to calculate the average for each test
Use a nested for loop to rint the Student names, test scores, student average. Use a single for loop to print the average for each test.
Highest strStudentArray Average is strStudentArray - Mark Lowest strStudentArray Average is strStudentArray - Mark
Part 2 - Cancelled |
Assignment 8.2- Bingo Card (Gui) Using a 2-D Array Generate a Bingo Card. Since we are not doing any calculations with the card it is easier if you make it a string and convert the random number to a string.
Make sure that there are no duplicate numbers in the card. Randomly Generate a number. Display each number that is called i.e. B 13 Indicate if it is on the card or not Mark the number on the card in some way.
Hints Generate Card Button to Create the Card. Use a nested for loop with col on the outside and row on the inside to generate each column. Initialize the random number min value to 1 and max value to 15 To check if the random number has already been generated use if
and while loop Outside the row loop but inside the col loop change the min and max values for the random number by 15.
printCard method You will need to assign the value of the bingocard to the appropriate text box using setText. Note: We cannot do this in a loop yet so you will need to do it individually. i.e. textBox00.setText (strBingoArray[0][0]); callNumber Button Generate a random number from 1 to 75. Check if it has already been called. If so generate a new number. Store the called number in an Array List See if the number is in the list Print the Array List Change the number in the bingo array to something else to show it has been called and re-print
|
Return Values From Methods Example 1 - Returning an Integer Value from a Method public class Program { public static void main(String[] args) {
}
Example 2 - Returning an Array from a method
|
Assignment 8.3 - intGradeArrays (Gui) Cancelled Create a strStudentArray intGradeArrays Application that simulates a intGradeArray book for a class with 15 strStudentArrays who each have four test scores.
This program is similar to the strStudentArray Records program that you created earlier The difference here is that you are now using a two-dimensional array which will allow you to store more information about each of the strStudentArrays. Requirements
|