Please provide solution in JAVA with Driver class using all the methods Please p
ID: 3702141 • Letter: P
Question
Please provide solution in JAVA with Driver class using all the methods
Please provide solution in JAVA with Driver class using all the methods
Please provide solution in JAVA with Driver class using all the methods
Please provide solution in JAVA with Driver class using all the methods
Please provide solution in JAVA with Driver class using all the methods
14 2 ayD Class Array2D ngetTotal(array : ?nt ID : int getTotal array : double In) : dou ble getAverage(array : ?nt nm : double getAveragefarray: double In: double getRowTotai(array : int ??. row : int) : int getRow Total(array: double II, row: int): double tqetColumnTotal(array : int nn. col : int) : int getColumnTotal array: double Il col : int) : double +getHighestinRow array: int In, row : int): int getHighestinRow array : double II, row: int): double getHighestinRow array: String Il, row : int): String getLowestinRowlarray: int II, row: int) int getLowestinRow aray : double II, row int): double getLowestinRow amay:String Il, row: int): StringExplanation / Answer
Executable code:
import java.util.*;
class Array2D{
//total sum of the 2D integer array is calculated by looping through entire array
int getTotal(int ar[][],int a,int b){
int total=0;
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
total=total+ar[i][j];
return total;
}
//total sum of the 2D double array is calculated by looping through entire array
double getTotal(double ar[][],int a,int b){
double total=0.0;
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
total=total+ar[i][j];
return total;
}
//total sum is calculated and the average is found out
double getAverage(int ar[][],int a,int b){
int total=0;
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
total=total+ar[i][j];
return (double) (total)/(a*b);
}
//total sum is calculated and the average is found out
double getAverage(double ar[][],int a,int b){
double total=0;
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
total=total+ar[i][j];
return (double) (total)/(a*b);
}
//for a given row number the sum of the elements in that row is calculated, variable row stores the row total to be calculated
int getRowTotal(int ar[][],int row,int b){
int total=0;
for(int j=0;j<b;j++)
total=total+ar[row-1][j];
return total;
}
//for a given row number the sum of the elements in that row is calculated, variable row stores the row total to be calculated
double getRowTotal(double ar[][],int row,int b){
double total=0;
for(int j=0;j<b;j++)
total=total+ar[row-1][j];
return total;
}
//for a given column number the sum of the elements in that column is calculated, variable col stores the column total to be calculated
int getColumnTotal(int ar[][],int a,int col){
int total=0;
for(int i=0;i<a;i++)
total=total+ar[i][col-1];
return total;
}
//for a given column number the sum of the elements in that column is calculated, variable col stores the column total to be calculated
double getColumnTotal(double ar[][],int a,int col){
double total=0;
for(int i=0;i<a;i++)
total=total+ar[i][col-1];
return total;
}
//for a given row number first element of that row is assumed high and compared with other elements of that row and the highest is returned
int getHighestInRow(int ar[][],int row,int b){
int high=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j]>high)
high=ar[row-1][j];
return high;
}
//for a given row number first element of that row is assumed high and compared with other elements of that row and the highest is returned
double getHighestInRow(double ar[][],int row,int b){
double high=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j]>high)
high=ar[row-1][j];
return high;
}
//for a given row number first element of that row is assumed high and compared with other elements of that row and the highest is returned
String getHighestInRow(String ar[][],int row,int b){
String high=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j].compareTo(high)>0)
high=ar[row-1][j];
return high;
}
//for a given row number first element of that row is assumed low and compared with other elements of that row and the lowest is returned
int getLowestInRow(int ar[][],int row,int b){
int low=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j]<low)
low=ar[row-1][j];
return low;
}
//for a given row number first element of that row is assumed low and compared with other elements of that row and the lowest is returned
double getLowestInRow(double ar[][],int row,int b){
double low=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j]<low)
low=ar[row-1][j];
return low;
}
//for a given row number first element of that row is assumed low and compared with other elements of that row and the lowest is returned
String getLowestInRow(String ar[][],int row,int b){
String low=ar[row-1][0];
for(int j=1;j<b;j++)
if(ar[row-1][j].compareTo(low)<0)
low=ar[row-1][j];
return low;
}
}
public class HelloWorld{
public static void main(String []args){
//object of the class Array2D is defined
Array2D obj=new Array2D();
//Arrays are intialised can be modified to be entered by user
int A[][]={{2,4,5},{5,7,10},{1,12,6}};
double B[][]={{2.2,5.6,9.8},{1.5,2.5,8.9}};
String C[][]={{"jack","jill"},{"mary","melanie"}};
System.out.println("Total of integer array = "+obj.getTotal(A,3,3));
System.out.println("Total of double array = "+obj.getTotal(B,2,3));
System.out.println("Average of integer array = "+obj.getAverage(A,3,3));
System.out.println("Average of integer array = "+obj.getAverage(B,2,3));
System.out.println("Row total 2nd row of integer array = "+obj.getRowTotal(A,2,3));
System.out.println("Row total 1st row of double array = "+obj.getRowTotal(B,1,3));
System.out.println("Column total 1st column of integer array = "+obj.getColumnTotal(A,3,1));
System.out.println("Column total 2nd column of double array = "+obj.getColumnTotal(B,2,2));
System.out.println("Highest in row 2 of integer array is = "+obj.getHighestInRow(A,2,3));
System.out.println("Highest in row 1 of double array is = "+obj.getHighestInRow(B,1,3));
System.out.println("Highest in row 2 of String array is = "+obj.getHighestInRow(C,2,2));
System.out.println("lowest in row 1 of integer array is = "+obj.getLowestInRow(A,1,3));
System.out.println("lowest in row 1 of double array is = "+obj.getLowestInRow(B,1,3));
System.out.println("Lowest in row 1 of String array is = "+obj.getLowestInRow(C,1,2));
}
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.