Introduction to Computer Programming 2
-
Program: ArrayMethods
-
Objective: To complete the program below designed to carry out the listed behaviors for an array of integers.
-
Incomplete program called ArrayMethods
public class ArrayMethods{
private int [] values;
public ArrayMethods(int [] initialValues)
{ values = initialValues;}
public void swapFirstAndLast(){…}
public void shiftRight(){…}
…
}
-
Behaviors to Complete
-
(swapFirstAndLast) Swap the first and last elements in the array.
-
(shiftRight) Shift all elements to the right by one and move the last element into the first position.
-
(replaceEven) Replace all even elements with 0. Note: Not the even indexes, the even elements.
-
(neighborSwitch) Replace each element, except the first and last, with the larger of its two neighbors.
-
(noMiddle) Remove the middle element if the array is odd, or the two middle elements if the array is even. Return a new array.
-
(secondLargest) Return the second largest element in the array.
-
(sorted) Return true if the array is sorting in increasing order.
-
(adjDups) Return true if the array has two adjacent duplicate elements.
-
(nonAdjDups) Return true if the array contains duplicate elements (which need not be adjacent.)
-
Notes
-
Read through the rubric for grading as a guide of expectations.
-
No tester class required.
-
Copying programs from each other is a direct violation of district policy.
-
All students need to email this program by Thursday 5/4/17.
-
This program is worth 45 points.
Share with your friends: |