
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Do the Random2DArray
And the tester is at the bottom
import java.util.Random;
/**
* Store a 2-D array and provide methods to
* get the average values of any row, any
* column, or the entire array.
*
* Step 1: Enter your name for @author and today's date for @version
* @author
* @version
*/
public class Random2DArray
{
public final int LOW_LIMIT = -10;
public final int HIGH_LIMIT = 10;
// Step 2: Declare an instance variable of a 2-D
// array of int
// Step 3: Complete the constructor
/**
* Constructs an object of class Random2DArray
* by initializing the instance variable to
* the passed in parameter.
*
* @param array a 2-D array of int
*/
public Random2DArray(int[][] array)
{
}
// Step 4: Complete the constructor
/**
* Constructs an object of class Random2DArray.
* It creates a 2-D array of int with the
* specified rows and columns for the instance
* variable, then creates a Random object with
* the specified seed and use it to fill the
* entire array with random numbers in the
* range of [LOW_LIMIT, HIGH_LIMIT].
*
* @param rows number of rows of the 2-D array
* @param cols number of columns of the 2-D array
* @param seed the seed of the Random generator
*/
public Random2DArray(int rows, int cols, int seed)
{
}
// Step 5: Complete method rowAverage()
/**
* Gets the average value of the specified row.
*
* You should use the enhanced for loop.
*
* @param rowIndex the index of the specified row
* @return the double average of the specified row
*/
public double rowAverage(int rowIndex)
{
}
// Step 6: Complete method colAverage()
/**
* Gets the average value of the specified column.
*
* @param colIndex the index of the specified column
* @return the double average of the specified column
*/
public double colAverage(int colIndex)
{
}
// Step 7: Complete method arrayAverage()
/**
* Gets the average value of the entire array.
*
* @return the double average of the entire array
*/
public double arrayAverage()
{
}
}
TESTER
public class Random2DArrayTester
{
public static void main(String[] args)
{
int[][] array123 = { {1, 2, 3, 4, 5, 6, 7},
{2, 3, 4, 5, 6, 7, 8},
{3, 4, 5, 6, 7, 8, 9} };
Random2DArray arrayOne = new Random2DArray(array123);
Random2DArray arrayTwo = new Random2DArray(5, 11, 123);
Random2DArray arrayThree = new Random2DArray(11, 5, -123);
int rowIndex = 0;
double average = arrayOne.rowAverage(rowIndex);
System.out.printf("The row average: %.2f.%n", average);
System.out.println("Expected: 4.00.");
average = arrayTwo.rowAverage(rowIndex);
System.out.printf("The row average: %.2f.%n", average);
System.out.println("Expected: -0.36.");
average = arrayThree.rowAverage(rowIndex);
System.out.printf("The row average: %.2f.%n", average);
System.out.println("Expected: -7.40.");
int colIndex = 2;
average = arrayOne.colAverage(colIndex);
System.out.printf("The column average: %.2f.%n", average);
System.out.println("Expected: 4.00.");
average = arrayTwo.colAverage(colIndex);
System.out.printf("The column average: %.2f.%n", average);
System.out.println("Expected: 1.00.");
average = arrayThree.colAverage(colIndex);
System.out.printf("The column average: %.2f.%n", average);
System.out.println("Expected: -2.00.");
average = arrayOne.arrayAverage();
System.out.printf("The average of the 2-D array: %.2f.%n", average);
System.out.println("Expected: 5.00.");
average = arrayTwo.arrayAverage();
System.out.printf("The average of the 2-D array: %.2f.%n", average);
System.out.println("Expected: -1.31.");
average = arrayThree.arrayAverage();
System.out.printf("The average of the 2-D array: %.2f.%n", average);
System.out.println("Expected: -0.27.");
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- Problem 11 of an Create a class ArraysAndMethodsGames, Write a method that returns the average array with the following header: public static double average(double[] array); Write a method to initialize the array with the following header: public static double[] readArray(): The readArray method prompts the user to enter ten double values and initializes a newly array with these values. It returns the array to main. The method main calls the method Method main prints the array as well. created average and prints the average. 8 Of 9 – SLCC, ASDV 1220, Lab17 Problem 12 Modify class ArraysAndMethodsGames by adding a method that finds the smallest element in an array of double values using the following header: public static double min(double[] array); Call it from main to test it with an array you create in main.arrow_forwardWhat transpires when a parameter for an array is sent in with either the ref or out keyword, and the results are observed?arrow_forwardStep 1: Read your files! You should now have 3 files. Read each of these files, in the order listed below. staticarray.h -- contains the class definition for StaticArray, which makes arrays behave a little more like Python lists O In particular, pay attention to the private variables. Note that the array has been defined with a MAX capacity but that is not the same as having MAX elements. Which variable indicates the actual number of elements in the array? staticarray.cpp -- contains function definitions for StaticArray. Right now, that's just the print() member function. 0 Pay attention to the print() function. How many elements is it printing? main.cpp -- client code to test your staticarray class. Note that the multi-line comment format (/* ... */) has been used to comment out everything in main below the first print statement. As you proceed through the lab, you will need to move the starting comment (/*) to a different location. Other than that, no changes ever need to be made to…arrow_forward
- 1Code a JavaScript callback function for the Array.map method to ('Yu Yamaguchi') evaluate an array of integersidentify the integers that are Prime numbersreturn the Prime numbers in the new array 2 Code a JavaScript callback function for the Array.reduce method to evaluate an array of integersdetermine the smalles integerreturn the smalles integer Note: if there are identical integers, the function is to return the last one.arrow_forwardJava Netbeansarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY