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

pleae help me write this class public class HeatPlate extends java.lang.Object T

ID: 3879529 • Letter: P

Question

pleae help me write this class

public class HeatPlate extends java.lang.Object

This class represents metal plate as a 2-dimensional grid of temperature values.

Field SummaryFields
 Modifier and TypeField and Description

1)private booleanconverged

A flag to indicated when we have reached convergence within the tolerance.

2) private doubleepsilon

A tolerance value used to determine whether two temperature values should be considered 'equal'.

3) static doubleMAX_TEMP

The maximum temperature allowed in our plate, 10000 Kelvin.

4) static doubleMIN_TEMP

The minimum temperature allowed in our plate, 0 Kelvin.

5) private intnumSteps

The number of steps computed so far.

6) private double[][]theValues

The array of double values representing discrete temperatures in our metal plate.

Constructor SummaryConstructors Constructor and DescriptionHeatPlate(double[][] initTemps)

Constructs a HeatPlate whose plate contains the temperatures as originally specified by initTemps.

HeatPlate(double toleranceIn, double[][] initTemps)

Constructs a HeatPlate whose plate contains the temperatures as originally specified by initTemps.

Method SummaryAll Methods Instance Methods Concrete Methods Modifier and TypeMethod and Description

1) private doublecomputeCell(int i, int j)

Computes a single cell value as the average of the neighbors.

2) intgetNumCols()

Returns the number of columns in the HeatPlate.

3) intgetNumRows()

Returns the number of rows in the HeatPlate.

4) doublegetTempAt(int row, int col)

Retrieves an individual temperature from the HeatPlate at a specified coordinate.

5) doublegetTolerance()

Getter method to retrieve the tolerance used for comparing values by this HeatPlate.

6) booleanhasConverged()

Tells us whether the HeatPlate has converged at equilibrium.

7) intnumberSteps()

Returns the total number of simulation steps that have been computed on this HeatPlate object.

8) voidsimulateStep()

This method must simulate a single step in the simulation given the current temperature values.

Explanation / Answer

here is your class : ------------------->>>>>>>>>>>>>

public class HeatPlate{
private boolean converged;
private double epsilon;
static double MAX_TEMP = 0;
static double MIN_TEMP = 1000;
private int numSteps;
private double[][] theValues;

public HeatPlate(double[][] initTemps){
  initializeTemp(initTemps);
}

public HeatPlate(double tolerence,double[][] initTemps){
  epsilon = tolerence;
  initializeTemp(initTemps);
}

private void initializeTemp(double[][] temp){
  theValues = new Double[temp.length][temp[0].length];
  for(int i = 0;i<temp.length;i++){
   for(int j = 0;j<temp[0].length;j++){
    theValues[i][j] = temp[i][j];
    if(MAX_TEMP < temp[i][j]){
     MAX_TEMP = temp[i][j];
    }
    if(MIN_TEMP > temp[i][j]){
     MIN_TEMP = temp[i][j];
    }
   }
  }

  converged = false;
}
private double compute(int i,int j){
  double res = 0;
  if(i == 0 && j == 0 ){
   res = (theValues[i+1][j] + theValues[i][j+1])/2;
  }else if(i == 0 ){
   res = (theValues[i+1][j] + theValues[i][j+1] + theValues[i][j-1])/3;
  }else if(j == 0 ){
   res = (theValues[i+1][j] + theValues[i][j+1]+theValues[i-1][j])/3;
  }else if(i == numRows()-1 && j == numCols()-1){
   res = (theValues[i-1][j] + theValues[i][j-1])/2;
  }else if(i == numRows()-1){
   res = (theValues[i-1][j] + theValues[i][j+1]+theValues[i][j-1])/3;
  }else if(j == numCols()-1){
   res = (theValues[i+1][j] + theValues[i-1][j]+theValues[i][j-1])/3;
  }else{
   res = (theValues[i+1][j] + theValues[i][j+1]+theValues[i-1][j]+theValues[i][j-1])/4;
  }

  return res;
}

int numRows(){
  return theValues.length;
}
int numCols(){
  return theValues[0].length;
}

double getTempAt(int i,int j){
  if(i > 0 && j > 0 && i < numRows() && j < numCols()){
   return theValues[i][j];
  }

  return 0;
}

double getTolerence(){
  return epsilon;
}

boolean hasConverged(){
  return converged;
}

int getNumSteps(){
  return numSteps;
}

void simulateSteps(){
  numSteps++;
  double temp;
  for(int i=0;i<numRows;i++){
   for(int j = 0;j<numCols;j++){
    temp = compute(i,j);
    if(abs(temp - theValues[i][j]) == epsilon){
     converged = true;
    }else{
     converged = false;
    }

    if(temp > MAX_TEMP){
     MAX_TEMP = temp;
    }

    if(temp < MIN_TEMP){
     MIN_TEMP = temp;
    }

    theValues[i][j] = temp;
   }
  }
}
}