Create a class called Lab7b and in it implement all of the methods below. Also, write a main method with test calls to all of these methods. Don’t forget to turn in your file to Canvas before the end of the lab today.
int[][] random(int N, int start, int end) returns an N-by-N matrix of random integers ranging from start to end;
int rowSum(int[][] a, int i) returns the sum of the elements in row i of the 2-D array a;
int colSum(int[][] a, int j) returns the sum of the elements in column j of the 2-D array a;
boolean isSquare(int[][] a) returns true if the 2-D array a is square (i.e. the number of rows and columns are the same);
boolean isLatin(int[][] a) returns true if the 2-D array a is a Latin square (i.e. an n-by-n matrix such that each row and each column contains the values from 1 through n with no repeats);
main(String[] args): the main method should test each method above on five randomly generated matrices and also these ones:
int[][] allneg = { {-10,-12,-3}, {-4,-5,-6,-8}, {-7,-8} }; int[][] nonsquare ={ {1,2,3}, {4,5}, {6,7,8,9} }; int[][] latin = { {1,2,3}, {2,3,1}, {3,1,2} }; int[][] notlatin = { {2,1,3}, {2,3,1}, {3,1,2} };
Note: The borders are produced at the time of printing. You also need to shift the numbers for each row of the 2D array as displayed below:
+-+-+-+-+-+ |1|2|3|4|5| +-+-+-+-+-+ |2|3|4|5|1| +-+-+-+-+-+ |3|4|5|1|2| +-+-+-+-+-+ |4|5|1|2|3| +-+-+-+-+-+ |5|1|2|3|4| +-+-+-+-+-+
Program for ShiftNumbers.java
Create a class called Lab7b and in it implement all of the methods below. Also, write...
In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...
Submit Chapter7.java with four (4) public static methods as follows: A. Write a method called mostCommon that accepts an array of integers as its only parameter, and returns the int that occurs most frequently. Break ties by returning the lower value For example, {1,2,2,3,4,4} would return 2 as the most common int. B. Write mostCommon (same as above) that accepts an array of doubles, and returns the double that occurs most frequently. Consider any double values that are within 0.1%...
Write a class named RowSort which has the following members. Private: (1) double matrix 0O (a 2D array): (2) int columns; (3) int rows Public: (1) A default constructor that creates a 2D array, 8 6 4 (2) A constructor that takes three values for the three private members, and creates a 2D array accordingly. (3) The "get" and "set" methods for the three private members. (4) A method that displays a 2D array, stored in the private member matrix,...
Java Here is the template public class ShiftNumbers { public static void main(String[] args) { // TODO: Declare matrix shell size // TODO: Create first row // TODO: Generate remaining rows // TODO: Display matrix } /** * firstRow * * This will generate the first row of the matrix, given the size n. The * elements of this row will be the values from 1 to n * * @param size int Desired size of the array * @return...
please answer in Java..all excercises. /** * YOUR NAME GOES HERE * 4/7/2017 */ public class Chapter9a_FillInTheCode { public static void main(String[] args) { String [][] geo = {{"MD", "NY", "NJ", "MA", "CA", "MI", "OR"}, {"Detroit", "Newark", "Boston", "Seattle"}}; // ------> exercise 9a1 // this code prints the element at row at index 1 and column at index 2 // your code goes here System.out.println("Done exercise 9a1.\n"); // ------> exercise 9a2 // this code prints all the states in the...
Can someone help me with this? Create a mini program including a main() method and void methods where arrays are nxn i.e. same no. of rows & columns 1. displayArray(): Takes one parameter, a 2D symmetrical int array called "symmetric" & print the array as shown in the sample output. 2. shiftTheRowsBelow(): Takes one parameter, a 2D symmetrical int array called "symmetric". It will take the given values in the last row of the array, move them to the first...
Please provide answer! (10) 3. Develop a method called set2DArray that given an integer number N creates and returns a 2D array with N rows and N columns initialized as follows: All elements on diagonal: 1 All elements above diagonal: row# + Column# All elements below diagonal: row# - Column#
In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...
This is for Java. Create ONE method/function that will return an array containing the row and column of the largest integer i the 2D array. If the largest number is located on row 2, column 1, the method needs to return row 2 and column one. Do not use more than one method. Use the code below as the main. Please comment any changes. in java Given the main, create a method that RETURNS the largest number found in the...
Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....