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

Create a callback class LengthMeasurer for the string. It will calculate the len

ID: 3795967 • Letter: C

Question

Create a callback class LengthMeasurer for the string. It will calculate the length of the string

.

Create a callback class AreaMeasurer for the rectangles. It will calculate the area of the rectangle.

Create and modify the Data class on page 479-481 to include the following classes.

Add a getMinimum method.

Add a getMax method.

Add an addOnlyEven method that adds only the even values.

Create a class called MeasurerTester. This tester should accomplish the following:

Create an array to hold 10 Strings.

Use a loop to ask the user for 10 strings. Put each string in the array.

Create another array to hold 10 Rectangles.

Use a loop to ask the user for the necessary input to create a rectangle and then put it in the array.

Run the Data class using the two types of data. For each type of data, print the average, minimum, maximum, median and addOnly Even.

The Data class looks like this

public class Data
{


/**

* Computes the average of the measures of the given objects.

@param objects an array of objects

@param meas the measurer for the objects

@return the average of the measures

*/
public static double average(Object[] objects,Measurer meas)
{
// initialise instance variables
double sum = 0;
for (Object obj: objects)
{
sum = sum + meas.measure(obj);
}
if(objects.length>0)
{
return sum/objects.length;
}
else
{
return 0;
}
}

Explanation / Answer

public class Data
{


/**

* Computes the average of the measures of the given objects.

@param objects an array of objects

@param meas the measurer for the objects

@return the average of the measures

*/
public static double average(Object[] objects,Measurer meas)
{
// initialise instance variables
double sum = 0;
for (Object obj: objects)
{
sum = sum + meas.measure(obj);
}
if(objects.length>0)
{
return sum/objects.length;
}
else
{
return 0;
}
}

private double getMinimum()

{

Double a=10;

Double b=1100;

double z=min (a,b);

return z;

}

private double getMax()

{

Double a1=10;

Double b1=1100;

double z1=min (a1,b1);

return z1;

}

private double addEven(double a[])

{

double sum=0;

For (int i=0;i<10;i++)

{

if(a[i[%2==0)

{

sum+=a[i];

}

}

}

}

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