Question: JAVA Programming Inside class ArrSum, write a standalone function/procedure called sum with the following header: public static int sum(int[] a) The method sum takes an
JAVA Programming
Inside class ArrSum, write a standalone function/procedure called sum with the following header:
public static int sum(int[] a)
The method sum takes an integer array as an argument, and returns the sum of all elements back to the caller.
Write appropriate specifications (precondition, postcondition, and frame properties using assignable/modifies) for sum that describe the behavior of sum to all potential clients. Make sure to also implement sum.
Write a driver class TestSum with at least 3 different calls to sum.
I wrote this, but my jvm gives me an error, if you can please fix it and do what the question asking please,
//ArrSum.java
public class ArrSum {
public static int sum (int[] a) {
//Precondition: sum to be a int array as an argument
//Modifies: a
//Postcondition: sum of all the integers
System.out.println("ArrSum Class");
a = 10;
return a;
}
//TestSum.java
class TestSum {
public static void main(String [] args){
//ArrSum ArrObject = new Arrsum();
//ArrObject.sum(x);
//System.out.println(ArrObject);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
