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

Given the following construct a UML diagram for Java: Design a class named locat

ID: 3832692 • Letter: G

Question

Given the following construct a UML diagram for Java:

Design a class named location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximum value and its indices in a two-dimensional array with row and column as int types and maxValue as double type.

Write the following method that returns the location of the largest element in two-dimensional array:

Public static Location locateLargest(double[][] a)

That return value is an instance of Location.

Explanation / Answer

HI, Please find my implementation.

Please let me knwo in case of any issue.

public class Location {

  

   // instance variables

   private int row, column;

   private double maxValue;

  

   // constructor

   public Location(int r, int c, double max) {

       row = r;

       column = c;

       maxValue = max;

   }

   // getters and setters

  

   public int getRow() {

       return row;

   }

   public int getColumn() {

       return column;

   }

   public double getMaxValue() {

       return maxValue;

   }

   public void setRow(int row) {

       this.row = row;

   }

   public void setColumn(int column) {

       this.column = column;

   }

   public void setMaxValue(double maxValue) {

       this.maxValue = maxValue;

   }

  

   // Method

   public static Location locateLargest(double[][] a){

      

       int r=0, c=0;

      

       double max = a[0][0];

      

       for(int i=0; i<a.length; i++){

           for(int j=0; j<a[i].length; j++){

              

               if(a[i][i] > max){

                   r = i;

                   c = j;

                   max = a[i][j];

               }

           }

       }

      

       return new Location(r, c, max);

   }

  

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote