CSE116     Introduction to Computer Science II     Spring 1999

Hwk1: Due date: 2/7 before midnight.

Submit on-line.

(1) (5 X 3 = 15 points) Write a class ArrayUtil that defines the following methods.

a. int sum(int[], int size) sums the elements A[0] to A[size-1].

b. int frequency(int[] A, int size, int p) counts the number of occurrences of p among the values A[0] to A[size-1].

c. int max(int [] A, int size) returns the maximum among the values A[0] to A[size-1].

d. void insert(int[] A, int size, int p) inserts p into A as the first element. The existing elements of A(A[0]..A[size-1]) are shifted over one position to the right; you can assume A is large enough to hold this new element.

e. int find(int[] A, int size, int p) returns the location at which p occurs first in A or -1 if it does not occur at all.

(2) (5 points) Write an application class Hwk1 that exercises the class ArrayUtil.

How to do it?

Submit one java file containing both classes.
Name it Hwk1.java It should the following comments at the beginning:
Name: Person Number: Class : CSE116A, CSE116B or CS504
// Hwk1 class
// ArrayUtil class

Save the file. Compile and test it. Debug. Submit on-line only the file Hwk1.java.

Please DO NOT submit executable .class files.

For submission use:
                       ~bina/submit_cse116a filename if you are in CSE116A and CS504
                       ~bina/submit_cse116b filename if you are in CS116B class