/*********************** * ArrayPractice.java -- YOU WRITE THESE! * @author your name here!! * @version 2019-Oct-ZZ * @see http://www.radford.edu/itec120/2019fall-ibarland/Homeworks/arrays/ * * Runnable tests for these methods are in TestArrayPractice.java. * * You must write the method headers, and they must be correct * in order for the tests to run. i.e. You can't change the name * of the method, and it must have the correct return type and * correct parameter types as described in each comment block. * * You may add methods to this file if you like. * Sometimes it is useful to make helper methods to do some * task you need to do several times. * * You may NOT use methods in java.util.Arrays or java.util.Collections. * You MAY use the charAt, length, equals (in Object120), * as well as class Math (e.g. Math.max) and Character. * * ***********************/ class ArrayPractice extends Object120 { /*********************** * * isTeency - answers if the given int is in [0,12]. * * isTeency(13) --> false * isTeency(19888) --> false * isTeency(1) --> true * isTeency(55) --> false * isTeency(7) --> true * isTeency(12) --> true * isTeency(-1) --> false * isTeency(-999) --> false * isTeency(0) --> true * ***********************/ /*********************** * * allTeency - takes an array of ints and returns true if every element * in the array is a teency number (as per above). * * allTeency([7,5,8,1]) --> true * allTeency([2,15,8]) --> false * allTeency([7]) --> true * allTeency([1,3,-4,9]) --> false * allTeency([]) --> false * ***********************/ /*********************** * * filterTeencies - takes an array of ints and returns a new array that contains * only the teency numbers (as per above) in the given array. * The returned array should be only long enough to hold the teency numbers. * The teency numbers in the returned array are in the same order that * they occur in the original array. * * filterTeencies([3,13,1,4,77]) --> [3,1,4] * filterTeencies([44,15,-9,17]) --> [] * filterTeencies([15,1,18]) --> [1] * filterTeencies([]) --> [] * ***********************/ /*********************** * * whichOnesAreTeency - takes an array of ints and returns an array of boolean * the same size as the given array. An element of the boolean * array is true if the corresponding int in the given array * is a teency number (as per above). * * whichOnesAreTeency([15,2,18889,4,7]) --> [false,true,false,true,true] * whichOnesAreTeency([44,20,-9,72]) --> [false,false,false,false] * whichOnesAreTeency([-5,7,56,123]) --> [false,true,false,false] * whichOnesAreTeency([3]) --> [true] * whichOnesAreTeency([33]) --> [false] * whichOnesAreTeency([]) --> [] * ***********************/ /*********************** * * combineArrays - takes two double arrays and returns an double array that is the product * of the elements of the two given arrays. The first element of * the returned array contains the product of the first elements of * the two given arrays, the second element is the product of two * second elements, and so on. If the two given arrays are not * the same length, the returned array is the length of the longer * one and the extra elements are simply the original value copied * to the same position in the returned array. For example: * * array1: [ 2, 3, 4 ] * times array2: [ 2, 2, 2, 2, 2 ] * ----------------------------------- * is result: [ 4, 6, 8, 2, 2 ] * * combineArrays( [2,2,2], [1,2,3,4,5] ) --> [2,4,6,4,5] * combineArrays( [1,2,3,4,5,6], [-3,-3,-3] ) --> [-3,-6,-9,4,5,6] * combineArrays( [4,4,4,4], [3,3,3,3,3] ) --> [12,12,12,12,3] * combineArrays( [], [1,2,3,4,5,6] ) --> [1,2,3,4,5,6] * combineArrays( [], [] ) --> [] * ***********************/ /*********************** * * digitsGoLast - takes an array of char and returns a new array of char with * the same elements except all the digits are moved to the end * of the array. Other than moving the digits to the end, all * characters appear in the order they did in the original array. * * digitsGoLast([A,9,B,8,7,C,6,D]) --> [A,B,C,D,9,8,7,6] * digitsGoLast([A,B,1,C,2,D]) --> [A,B,C,D,1,2] * digitsGoLast([N,o,n,u,m,s]) --> [N,o,n,u,m,s] * digitsGoLast([3,4,5]) --> [3,4,5] * digitsGoLast([4,^]) --> [^,4] * digitsGoLast([]) --> [] * ***********************/ /*********************** * * changeMaxesToMin - takes an array of int and replaces every occurrence of the * highest value in the array with the lowest value in the array. * The method changes the given array and does not return anything. * * changeMaxesToMin([5,3,8,8,7]) changes the given array to: [5,3,3,3,7] * changeMaxesToMin([22,1,22]) changes the given array to: [1,1,1] * changeMaxesToMin([]) makes no changes to an empty array * ***********************/ }