The assignment is to implement the interface provided and test the implementatio
ID: 3568930 • Letter: T
Question
The assignment is to implement the interface provided and test the implementation using the driver
class provided. I need help with interfaces. Please show me what is expected on this project
public interface ArrayFunctionsInterface
{
public double [ ] sortMe(double [ ] array);///returns a new array
public double getMax(double [ ] array);
public double getMin(double [ ] array);
public int whereAmI(double [ ] array, double searchValue);
public double sumMeUp(double [ ] array);
public double [ ] reverseMe(double [ ] array); //returns a new array
public void printMe(double [ ] array);
public double[ ] doubleMySize(double [ ] array); //returns a new array
}
The Driver:
public class Driver
{
public static void main(String [ ] args)
{
double [ ] testArray = {3, 6, 2, 5, 8, 4, 1, 7};
double [ ] results;
ArrayFunctions af = new ArrayFunctions( );
System.out.println("This is the original array: ");
af.printMe(testArray);
System.out.println(" This is a test of the sortMe( ) method and the printMe( ) methods. ");
results = af.sortMe(testArray);
af.printMe(results);
System.out.println(" This is a test of getMax( )");
System.out.println("The maximum value in the array is: " +af.getMax(testArray));
System.out.println(" This is a test of getMin( )");
System.out.println("The minimum value in the array is: " + af.getMin(testArray));
System.out.println(" This is a test of sumMeUp( )");
System.out.println("The sum of the values in the array is: " +af.sumMeUp(testArray));
System.out.println(" This is a test of reverseMe( )");
results = af.reverseMe(testArray);
af.printMe(results);
System.out.println(" This is a test of whereAmI( )");
System.out.println("The value 8 is at subscript " + af.whereAmI(testArray, 8));
System.out.println("This is a test of when search item is not in the array: ");
if(af.whereAmI(testArray, 505) == -1)
{
System.out.println("Data value is not in the array");
}
else
{
System.out.println("Data value is found at position " + af.whereAmI(testArray, 505));
}
System.out.println(" This is a test of doubleMySize( )");
testArray = af.doubleMySize(testArray);
af.printMe(testArray);
System.out.println(" End of tests");
} //end of main( )
Explanation / Answer
public class ArrayFunctions implements ArrayFunctionsInterface
{
public double[] sortMe(double[] array)
{
for(int i=0;i<array.length;i++)
{
for(int j=i;j<array.length;j++)
{
if(array[i]<array[j])
{
double a=array[i];
array[i]=array[j];
array[j]=a;
}
}
}
return array;
}
public double getMax(double[] array) {
double max=Double.MIN_VALUE;
for(int i=0;i<array.length;i++)
{
if(array[i]>max)max=array[i];
}
return max;
}
public double getMin(double[] array) {
double min=Double.MAX_VALUE;
for(int i=0;i<array.length;i++)
{
if(array[i]<min)min=array[i];
}
return min;
}
public int whereAmI(double[] array, double searchValue)
{
int ret=-1;
for(int i=0;i<array.length;i++)
{
if(array[i]==searchValue){ret=i;break;}
}
return ret;
}
public double sumMeUp(double[] array)
{
double sum=0;
for(int i=0;i<array.length;i++)
{
sum+=array[i];
}
return sum;
}
public double[] reverseMe(double[] array)
{
double rev[]=new double[array.length];
for(int i=0;i<array.length;i++)
rev[array.length-i-1]=array[i];
return rev;
}
public void printMe(double[] array) {
String s="";
for(int i=0;i<array.length;i++)
s+=array[i]+" ";
System.out.println(s);
}
public double[] doubleMySize(double[] array) {
double dum[]=new double[2*array.length];
for(int i=0;i<dum.length;i++)
{
if(i<array.length)dum[i]=array[i];
else dum[i]=0;
}
return dum;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.