Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PEARSON Search Programming Exercise 9.13 (The Location class) Design a class nam

ID: 3914480 • Letter: P

Question

PEARSON Search Programming Exercise 9.13 (The Location class) Design a class named Location for locating a maximal value and The class contains public data fields row, column, and and column as int types and maxValue as a double type Winite the folowing method that returns the location of the largest element in a two-dimensional array its location in a two-dimensional array maxValue that store the maximal value and its indices in a two-dimensional array with row public static Location locatelargest (doublet1t) a) The return value is an instance of Location. Wirite a test program that prompts the user to enter a two-dimensional array and displays the location of the largest element in the array SAMPLE RUN: Enter the number of rows and columns in the array: 3 4 Enter the array: 23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6 The location of the largest element is 45 at (, 2) Class Name. Exercise89 13 If you get a logical or runtime error, please refer https /Miveexample pearsoncmg.comvfaq html

Explanation / Answer

public class Location {

public int row;
public int col;
public double maxValue=0;
//function to find the largest element in the given array
public static Location locateLargest(double[][] a){
Location location = new Location();
location.maxValue = a[0][0];
location.row =0;
location.col = 0;
for(int i = 0; i <a.length;i++){
for(int j = 0; j<a[0].length; j++){
if (a[i][j]>location.maxValue) {
location.maxValue = a[i][j];
location.row = i;
location.col = j;
}
}
}
  
return location;
  
}
}

import java.util.Scanner;

public class driver extends Location{
public static void main(String[] args) {
Location location; //create a instances of a class
int r, c; //row and col value must be int
Scanner input = new Scanner(System.in); //create an object for scanner class
System.out.print(" Enter the row and column in the array :"); //prompt the user to enter the values
r = input.nextInt(); //accept the row value
c = input.nextInt();//accept the col value
double arr[][] = new double[r][c]; //declare the 2d array
System.out.println("Enter the array elements :"); //prompt the user to enter the elements of the array
for(int i = 0; i <r;i++){
for(int j = 0; j<c; j++){
arr[i][j]=input.nextDouble();
}
}
  
location = Location.locateLargest(arr); //call the memberfunction of Location and copy to location
//display the location values
System.out.println("The Location of the largest number is : "+location.maxValue+" at ("+location.row+" ,"+location.col+")" );
}
  
}

Output:

Enter the row and column in the array :3
4
Enter the array elements :
23.5
35
2
10
4.5
3
45
3.5
35
44
5.5
9.6
The Location of the largest number is : 45.0 at (1 ,2)
BUILD SUCCESSFUL (total time: 41 seconds)