Implement the following Java interface. Submit both the interface code provided
ID: 3719335 • Letter: I
Question
Implement the following Java interface. Submit both the interface code provided here and your class that implements the interface. **Note- take note of the return value for any method in the interface. **if the return value is an array of double (double[ ]) this ** means that a new array is returned and the original **array is not changed. This is not a new requirement. **This is a clarification in case you did not remember **that an array is an object . For 50 points extra credit, implement this interface and also implement the same interface using generics (take out the some-me-up method).
/**
* This interface specifies several
* methods for operations on an array of double
* (or int) values.
*
* An interface in Java 7 is made up of method headings only.
* These are abstract methods. The interface is abstract as well but
* because the Java compiler already "knows" this, you do not use the
* keyword abstract in the class heading.
*
* If there are any fields specified, they must be public, static, and
final.
* Because an interface is abstract, an interface cannot be instantiated.
*
* An interface is used for design purposes and for allowing classes to
be considered
* various types. In Java, you can only inherit from one superclass, but
a class can implement
* many interfaces.
*
* What a programmer does is implement an interface. This means the
programmer must override every
* method in the interface.
*
* @author
* @version
*/
public interface ArrayFunctionsInterface
{
double [ ] sortMe(double [ ] array);
double getMax(double [ ] array);
double getMin(double [ ] array);
int whereAmI(double [ ] array, double searchValue);
double sumMeUp(double [ ] array);
double [ ] reverseMe(double [ ] array);
void printMe(double [ ] array);
double[ ] doubleMyCapacity(double [ ] array);
}
For 50 points extra credit, implement this interface and
also implement the same interface using generics (take out
the some-me-up method).
Explanation / Answer
here is your code :===========????????
public interface ArrayFunctionsInterface
{
double[] sortMe(double[] array);
double getMax(double[] array);
double getMin(double[] array);
int whereAmI(double[] array, double searchValue);
double sumMeUp(double[] array);
double[] reverseMe(double[] array);
void printMe(double[] array);
double[] doubleMyCapacity(double[] array);
}
public class DoubleArray implements ArrayFunctionsInterface{
double[] sortMe(double[] array){
double[] arr = new double[array.length];
for(int i = 0;i<array.length;i++){
arr[i] = array[i];
}
double temp;
for(int i = 0;i<arr.length;i++){
for(int j = i+1;j<arr.length;j++){
if(arr[i] > arr[j]){
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
double getMax(double[] array){
if(array == null){
return -1;
}
double max = array[0];
for(int i = 1;i<array.length;i++){
if(array[i] > max){
max = array[i];
}
}
return max;
}
double getMin(double[] array){
if(array == null){
return -1;
}
double min = array[0];
for(int i = 1;i<array.length;i++){
if(array[i] < min){
min = array[i];
}
}
return min;
}
int whereAmI(double[] array, double searchValue){
if(array == null){
return -1;
}
for(int i = 0;i<array.length;i++){
if(searchValue == array[i]){
return i;
}
}
return -1;
}
double sumMeUp(double[] array){
if(array == null){
return -1;
}
double sum = 0;
for(int i = 0;i<array.length;i++){
sum += array[i];
}
return sum;
}
double[] reverseMe(double[] array){
double[] arr = new double[array.length];
for(int i = array.length-1,j = 0;i>=0;i--,j++){
arr[j] = array[i];
}
return arr;
}
void printMe(double[] array){
if(array == null){
return;
}
for(int j = 0;j>=0;j++){
System.out.println(array[i]+" ");
}
}
double[] doubleMyCapacity(double[] array){
double[] arr = new double[array.length * 2];
for(int i = 0;i<array.length;i++){
arr[i] = array[i];
}
return arr;
}
}