Hi, I am programming in java. The instructions require:Create a new project and call it Project8.Create a dual array 10x10 and initialize it with random numbers, range 0 to 100.Example: int[][] ary = new int[10][10];Create a method that finds the largest number in the array.Create a method that calculates the sum of a single row. Make the method flexible such that it can calculate the sum of any specified row.Display the sum of each row. The code must be well structured, use method where possible.  Please include detailed information and steps to how to solve this. Thank you! This is what I have thus far://Brianna Fisher COMP 1000import java.util.Random;import java.util.Arrays;public class Project8{static int ary; public static void main(String[] args){int[][] ary = new int[10][10];Random rnd = new Random (-1);for(int row = 0; row < 10; row++) {for(int col = 0; col < 10; col++) {ary[row][col] = rnd.nextInt(100);}}for(int row = 0; row < 10; row++)for(int col = 0; row <10; col++){System.out.println(Arrays.toString(ary[row]));}

Question
Asked Nov 21, 2019
21 views

Hi, I am programming in java. The instructions require:

Create a new project and call it Project8.

Create a dual array 10x10 and initialize it with random numbers, range 0 to 100.

Example: int[][] ary = new int[10][10];

Create a method that finds the largest number in the array.

Create a method that calculates the sum of a single row. Make the method flexible such that it can calculate the sum of any specified row.

Display the sum of each row. 

The code must be well structured, use method where possible. 

 

Please include detailed information and steps to how to solve this. Thank you!

 

This is what I have thus far:

//Brianna Fisher COMP 1000
import java.util.Random;
import java.util.Arrays;

public class Project8
{

static int ary;

 

public static void main(String[] args)
{

int[][] ary = new int[10][10];
Random rnd = new Random (-1);

for(int row = 0; row < 10; row++)
{
for(int col = 0; col < 10; col++)
{
ary[row][col] = rnd.nextInt(100);
}
}

for(int row = 0; row < 10; row++)
for(int col = 0; row <10; col++)
{
System.out.println(Arrays.toString(ary[row]));

}

check_circle

Expert Answer

Step 1

Program algorithm-

START

Step1: Import the essential java packages.

Step2: Define the class Project8

Step3: Define the main method.

Step4: Prompt the user to enter the row number to display the sum of specific row.

Step5: Declare all the variables and their datatypes accordingly.

Step6: Define a 2-D array as int datatype.

Step7: Use for loop to iterate over rows and columns

Step8: Define a non-static method to calculate the sum of each row individually.

Step9: Display the highest number in the array.

Step10: Call the non-static method from static method to display all the rows on the console.

END

Step 2

Code (in java)-

import java.util.Scanner;

public class Project8

 

{

 

//Declare and initialize the static variable

 

public static final int n = 11,m=11;

 

//Create Scanner object

 

Scanner in=new Scanner(System.in);

 

//Define the function to find the largest in an array

 

void highest(int[][] ary)

 

{

 

//Set first array value as maximum

 

int maxm=ary[0][0];

 

//Create "for" loop to iterate over row

 

for(int row=1;row<=10;row++)

 

{

 

//Create "for" loop to iterate over column

 

for (int col=1;col<=10;col++)

 

{

 

//Check whether the array element is greater than maximum

 

if(ary[row][col]>maxm)

 

//Assign the maximum value

 

maxm=ary[row][col];

 

}

 

}

 

//Print the largest value in an array

 

System.out.println("The highest element in the array is  "+maxm);

 

}

 

//Define the method to display the sum of specified row

 

public void sumsinglerow(int[][] ary)

 

{

 

//Declare and initialize necessary variables

 

int c=0;

 

int sum=0;

 

int sumOfrow= 0;

 

//Prompt the user to enter the row

 

System.out.print("Enter the row number to display the sum: ");

 

//Get the row from the user

 

int sp=in.nextInt();

 

//Create "for" loop to iterate over row

 

for(int row=1;row<=10;row++)

 

{

 

//Create for loop to iterate over column

 

for(int col=1;col<=10;col++)

 

{

 

//Calculate sum of the row elements

 

sumOfrow+=ary[row][col];

 

//Increase the counter variable

 

c++;

 

//Check whether the count is "10"

 

if(c==10)

 

{

 

//Calculate the total sum value

 

sum+=sumOfrow;

 

//Check whether the current row is equal to the specified row

 

if(row==sp)

 

//Print the sum of specified row

 

System.out.println("The sum of specified row "+sp+" is :"+sumOfrow);

 

//Set count to "0"

 

c=0;

 

//Set the value to "0"

 

sumOfrow=0;

 

}

 

}

 

}

 

}

 

//Defining the main method

 

public static void main(String[] args)

 

{

 

//Declare and initialize all the necessary variables

 

int c=0;

 

int sum=0;

//Defining array

int[][] ary = new int[n][m];

 

int sumOfrow= 0;

 

//Create object

 

Project8 r=new Project8();

 

//Creating for loop to iterate over each row

 

for(...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What are the benefits of using a vector over an array?

A: Vector - It is a data structure used to store data.Vectors can be implemented as dynamic arrays with...

question_answer

Q: Define a function CoordTransform() that transforms its first two input parameters xVal and yVal into...

A: This program takes two inputs from the user. The CoordTransform() function is used to transform the ...

question_answer

Q: I need to answer for question no. 2

A: Given that the page size in the system is 4 KB. Using the table and the formulas, the following are ...

question_answer

Q: when an orginization undertakes an infosec-driven review of job descriptions, which job descriptions...

A: Information security: Data security(Infosec) is data assurance inside the association; it oversees i...

question_answer

Q: Given the following business rules, define the relationships between entities and identify cardinali...

A: Entity-Relationship (ER) diagram:The following ER diagram defines the cardinalities and relationship...

question_answer

Q: Perform this binary division and find the remainder: 10111101 / 1001   If possible can you help unde...

A: Binary NumberThe number system which has a base- 2 is called binary number system. It has only 2 sym...

question_answer

Q: What is the new risk management framework initiative? How is it superior to the previous approach fo...

A: The New risk management framework initiative:It is the NIST special publication 800-37, this is the ...

question_answer

Q: I have written a C++ class called 'Birthday' and I want to write a method that can compare with anot...

A: Programming instructions:First, create the constructor to initialize the variables with the initial ...

question_answer

Q: Create a project called Mileage. In it, create a class Car with the following properties. A car has ...

A: Program:package Mileage;public class Car {private double fuelLevel;private double fuelEfficiency;pub...