Introduction to Computer Programming 2



Download 8.55 Kb.
Date05.08.2017
Size8.55 Kb.
#26655

Introduction to Computer Programming 2


  1. Program: ArrayMethods



  1. Objective: To complete the program below designed to carry out the listed behaviors for an array of integers.



  1. Incomplete program called ArrayMethods

public class ArrayMethods{

private int [] values;

public ArrayMethods(int [] initialValues)

{ values = initialValues;}

public void swapFirstAndLast(){…}

public void shiftRight(){…}



}


  1. Behaviors to Complete



    1. (swapFirstAndLast) Swap the first and last elements in the array.

    2. (shiftRight) Shift all elements to the right by one and move the last element into the first position.

    3. (replaceEven) Replace all even elements with 0. Note: Not the even indexes, the even elements.

    4. (neighborSwitch) Replace each element, except the first and last, with the larger of its two neighbors.

    5. (noMiddle) Remove the middle element if the array is odd, or the two middle elements if the array is even. Return a new array.

    6. (secondLargest) Return the second largest element in the array.

    7. (sorted) Return true if the array is sorting in increasing order.

    8. (adjDups) Return true if the array has two adjacent duplicate elements.

    9. (nonAdjDups) Return true if the array contains duplicate elements (which need not be adjacent.)



  1. Notes

    1. Read through the rubric for grading as a guide of expectations.

    2. No tester class required.

    3. Copying programs from each other is a direct violation of district policy.

    4. All students need to email this program by Thursday 5/4/17.

    5. This program is worth 45 points.

Directory: site -> handlers

Download 8.55 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page