This is for JAVA programming.
Create a test class that contains two arrays and two
methods:
- The first array has 3 rows and 3 columns and is initialized with
type double data
- The second array has 4 rows and 4 columns and is also initialized
with type double data
- The first method ArraysRows will receive an
array of type double as an argument and then print out the sum and
average of all elements in each ROW. Do
NOT pass any other parameters into the method
except for the array.
- The second method ArrayColumns will receive an
array of type double as an argument and then print out the sum and
average of all elements in each COLUMN. Do
NOT pass any other parameters into the method
except for the array.
- Array1 = {{5.0, 4.0, 3.0}, {6.0, 4.0, 5.0}, {2.0, 3.0,
4.0}}
- Array2 = {{5.0, 4.0, 3.0, 4.0}, {6.0, 4.0, 5.0, 5.0}, {2.0, 3.0,
4.0, 3.0}, {1.0, 2.0, 3.0, 2.0}}
Do NOT code any numerical literals into your
code.
public class TestArrays {
public static void main(String[] args) {
double[][] Array1 = { { 5.0, 4.0,
3.0 }, { 6.0, 4.0, 5.0 }, { 2.0, 3.0, 4.0 } };
double[][] Array2 = { { 5.0, 4.0,
3.0, 4.0 }, { 6.0, 4.0, 5.0, 5.0 }, { 2.0, 3.0, 4.0, 3.0 },
{ 1.0, 2.0, 3.0, 2.0 } };
ArraysRows(Array1);
System.out.println();
System.out.println();
ArraysColumns(Array2);
}
private static void ArraysRows(double[][] arr)
{
for (int i = 0; i < arr.length;
i++) {
double sum =
0;
for (int j = 0;
j < arr[i].length; j++) {
sum += arr[i][j];
}
System.out.println("Sum of Row" + i + ": " + sum);
System.out.println("Averagae of Row" + i + ": " + (sum /
arr[i].length));
}
}
private static void ArraysColumns(double[][] arr)
{
for (int i = 0; i <
arr[0].length; i++) {
double sum =
0;
for (int j = 0;
j < arr.length; j++) {
sum += arr[j][i];
}
System.out.println("Sum of Col" + i + ": " + sum);
System.out.println("Averagae of Col" + i + ": " + (sum /
arr.length));
}
}
}
This is for JAVA programming. Create a test class that contains two arrays and two methods:...
Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...
(10 pts) Define a two-dimensional array named temp with three rows and four columns of type int such that the first row is initialized to 6, 8, 12, 9; the second row is initialized to 10, 13, 6, 16; and the third row is initialized to 27, 5, 10, 20. (10 pts) Consider the following declarations, and see p.566: enum brands = { GM, FORD, TOYOTA, BMW, KIA }; const int N_BRANDS = 5; const int COLOR_TYPES = 6; double...
Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...
Define a two-dimensional int array which has 5 rows and 3 columns. The elements in array is randomly initialized (using Math.random()). Write a method to find the maximum value in this two dimensional array; Write a method to find the average value in the array; Write a method to count how many elements are smaller than average; Write a method to copy contents in a two-dimensional array to a one-dimensional array. The method will return this one-dimensional array. Method is...
Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods: getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. getAverage. This method should accept a two-dimensional array...
JAVA I. Using the Event Class created previously, create an array of objects; II. Demonstrate passing array reference to a method; III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...
This is the contents of Lab11.java import java.util.Scanner; import java.io.*; public class Lab11 { public static void main(String args[]) throws IOException { Scanner inFile = new Scanner(new File(args[0])); Scanner keyboard = new Scanner(System.in); TwoDArray array = new TwoDArray(inFile); inFile.close(); int numRows = array.getNumRows(); int numCols = array.getNumCols(); int choice; do { System.out.println(); System.out.println("\t1. Find the number of rows in the 2D array"); System.out.println("\t2. Find the number of columns in the 2D array"); System.out.println("\t3. Find the sum of elements...
Write a java program to sort arrays using 3 different methods: Bubble Sort, Selection Sort and Insertion Sort. The numbers to be sorted will be obtained using a library function which generates pseudo-random numbers. TO Do 1. Fill an array with 140 real numbers between 0.00 and 945.00. Generate the numbers using the subroutine that generates random numbers. Make a spare copy of the array; you will need it later. 2. Call a subroutine to print the contents of the...
JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class) 1) Data members: none 2) Methods a. A method named displayContents that accepts an array of type int and prints their values to the b. A method named cemoveNegatives that accepts an array of type int, copies all its non-negative the new array should be the...
Chapter 7 Exercise 18, Introduction to Java Programming, Tenth Edition Y. Daniel Liang. Please write your own code. 7.18 (Bubble sort) Write a sort method that uses the bubble-sort algorithm. The bubblesort algorithm makes several passes through the array. On each pass, successive neighboring pairs are compared. If a pair is not in order, its values are swapped; otherwise, the values remain unchanged. The technique is called a bubble sort or sinking sort because the smaller values gradually “bubble” their...