/*********************** * * HW5Srv - Array methods -- YOU WRITE THESE! * Tests for these methods are in TestHW5.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. * * Author: your name here!! * Date: 2019-Mar * ***********************/ public class HW5Srv { /*********************** * * isTeen - answers if the given int is a teen number, namely, 13 through 19, inclusive. * * isTeen(13) --> true * isTeen(19) --> true * isTeen(15) --> true * isTeen(12) --> false * isTeen(20) --> false * isTeen(4) --> false * isTeen(-17) --> false * isTeen(0) --> false * ***********************/ /*********************** * * allTeens - takes an array of ints and returns true if every element * in the array is a teen number, 13 through 19, inclusive. * * allTeens([17,15,18,15]) --> true * allTeens([12,15,18]) --> false * allTeens([17]) --> true * allTeens([-14,-16]) --> false * allTeens([]) --> false * ***********************/ /*********************** * * justTeens - takes an array of ints and returns a new array that contains * only the teen numbers in the given array (13 through 19, inclusive). * The returned array should be only long enough to hold the teen numbers. * * justTeens([3,12,1,4,77]) --> [] * justTeens([44,15,-9,17]) --> [15,17] * justTeens([15,16,18]) --> [15,16,18] * justTeens([]) --> [] * ***********************/ /*********************** * * whichOnesAreTeen - 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 teen number (13 through 19, inclusive). * * whichOnesAreTeen([15,12,18,14,77]) --> [true,false,true,true,false] * whichOnesAreTeen([44,20,-9,72]) --> [false,false,false,false] * whichOnesAreTeen([-5,17,56,123]) --> [false,true,false,false] * whichOnesAreTeen([13]) --> [true] * whichOnesAreTeen([33]) --> [false] * whichOnesAreTeen([]) --> [] * ***********************/ /*********************** * * combineArrays - takes two int arrays and returns an int array that is the sum * of the elements of the two given arrays. The first element of * the returned array contains the sum of the first elements of * the two given arrays, the second element is the sum 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. For example: * * array1: [ 1, 1, 1 ] * plus array2: [ 2, 2, 2, 2, 2 ] * ----------------------------------- * is result: [ 3, 3, 3, 2, 2 ] * * combineArrays( [1,1,1], [2,2,2,2,2] ) --> [3,3,3,2,2] * combineArrays( [2,2,2,2,2], [1,1,1] ) --> [3,3,3,2,2] * combineArrays( [], [1,2,3,4,5, 6] ) --> [1,2,3,4,5,6] * combineArrays( [], [] ) --> [] * ***********************/ /*********************** * * digitsInFront - takes an array of char and returns a new array of char with * the same elements except all the digits are in the front * of the array. The digits should appear in the same order as they * are in the original array, and all the remaining chars should * be in the same order as they are in the original array. * * digitsInFront([A,B,1,C,2,D]) --> [1,2,A,B,C,D] * digitsInFront([N,o,n,u,m,s]) --> [N,o,n,u,m,s] * digitsInFront([3,4,5]) --> [3,4,5] * digitsInFront([$,4]) --> [4,$] * digitsInFront([]) --> [] * ***********************/ /*********************** * * hiForLo - takes and array of int puts replaces every occurrence of the * lowest value in the array with the highest value in the array. * The method changes the given array and does not return anything. * * hiForLo([5,3,8,3,7]) changes the given array to: [5,8,8,8,7] * hiForLo([1,1,22]) changes the given array to: [22,22,22] * hiForLo([]) makes no changes to an empty array * ***********************/ }