Question: COMPLETE THE JUNIT SO ALL TESTS PASS: /** * Name: First, Last * Only turn this file in to the dropbox. Only use AP official
COMPLETE THE JUNIT SO ALL TESTS PASS:
/**
* Name: First, Last
* Only turn this file in to the dropbox. Only use AP official
* subset methods for ArrayLists, Strings, 1D arrays, etc. Focuses on Chapter 7 in the EText
*
* @version 1.1 - shifted order to match tests.
*/
public class JU20V
{
// Declare any constants up here.
/**
* Using a regular FOR loop, build a single sentence out of all of the names
* in the names array. Example:
*
*
* sayNamesRegularFOR({"Grace","Steve","Ada"})
* -> "
" *
*
* @param names
* @return
*/
public static String sayNamesRegularFOR(String[] names)
{
// You MUST use a regular FOR loop to solve this.
String sentence = "Start:";
return sentence;
}
/**
* Using a FOR EACH loop, build a single sentence out of all of the names in
* the names array. Example:
*
*
* sayNamesFOREACH({"Grace","Steve","Ada"})
* -> "
" *
*
* @param names
* @return
*/
public static String sayNamesFOREACH(String[] names)
{
// Remember to do this using a FOR EACH loop.
// These are discussed at the bottom of page 233 in the
// ebook.
String sentence = "Start:";
return sentence;
}
/**
* Using a regular FOR loop, given an array, simply count the number of 42's
* you find in the array. Related to: sequential search
*
*
* For example,
* arr = {5, 3, 8, 42, 9, 42, 9, 42, 42}
* then
* warmUpCount42s(arr) -> 4
*
*
* @param arr
* @return
*/
public static int warmUpCount42RegularFOR(int[] arr)
{
// TODO: Need to complete.
// Hint: You can use a normal FOR loop here. Do not use a FOR EACH loop.
return 42;
}
/**
* Given four Strings, create an array and fill it with those strings in the
* order given. So if name1 = "A", name2 = "Barry", name3 = "C", name4 = "D",
* then the array would look:
*
*
* {"A", "Barry", "C", "D"}
*
*
* @param name1
* @param name2
* @param name3
* @param name4
* @return
*/
public static String[] fillArrayWithNames(String name1, String name2,
String name3, String name4)
{
// TODO: Finish
return null; // not the correct answer.
}
/**
* Using a FOR EACH loop, given an array, simply count the number of 42's you
* find in the array. Related to: sequential search
*
*
* For example,
* arr = {5, 3, 8, 42, 9, 42, 9, 42, 42}
* then
* warmUpCount42s(arr) -> 4
*
*/
public static int warmUpCount42FOREACH(int[] arr)
{
// TODO: Need to complete.
// Hint: You can use a FOR EACH loop here.
return 42;
}
/**
* Creates an array filled with whole numbers starting at zero and ending at
* max.
*
*
* createArrayOfWholeNumbers(4) would return {0, 1, 2, 3, 4}
*
*
* @param max
* @return
*/
public static int[] createArrayOfWholeNumbers(int max)
{
// TODO: Finish
// Big hint is on page 241 in the Ebook
return new int[5]; // not the correct answer.
}
/**
* Takes an array, creates a new array with the opposite values.
*
* @param itemArray
* @return
*/
public static boolean[] reverseTheTruth(boolean[] itemArray)
{
// TODO: Finish
return new boolean[3]; // not the correct answer.
}
/**
* Creates a new array with values that are double the values in the original
* array. itemArray is NOT changed after the call to doubleAllOfThem
*
*
* Example
* stuff == {2, 3, -4, 8, 0, 1}
* thingy = doubleAllOfThem(stuff);
* thingy == {4, 6, -8, 16, 0, 2}
* stuff == {2, 3, -4, 8, 0, 1}
*
*
* @param itemArray
* @return
*/
public static int[] doubleAllOfThem(int[] itemArray)
{
// TODO: Finish
return new int[3]; // not the correct answer.
}
/**
* Creates a new array using the values of myArray and yourArray. Basically
* you are creating a new array by stitching the first array with the second.
*
*
* stuff1 = {1, 4, 2}
* stuff2 = {5, 3};
* stuff3 = appendArrays(stuff1, stuff2);
* stuff3 == {1, 4, 2, 5, 3};
*
*
* @param myArray
* @param yourArray
* @return
*/
public static int[] appendArrays(int[] myArray, int[] yourArray)
{
// TODO: Finish
return new int[8]; // not the correct answer.
}
/**
* Returns true if the numbers in the values array contain four numbers that
* have the same value.
*
*
* isConsecutiveFour({3, 4, 5, 5, 5, 5, 4, 5}) -> true
* isConsecutiveFour({3, 4, 5}) -> false
* isConsecutiveFour({1, 1, 1, 1, 1, 4}) -> true
*
*
* @param values
* is not null
* @return true or false
*/
public static boolean isConsecutiveFour(int[] values)
{
// A big hint can be found if you sign into your EText and then
// watch the video on this exact problem.
// https://mediaplayer.pearsoncmg.com/assets/secs-liang-pr-Consecutive_Four?
// TODO: Finish
return false;
}
/**
* Given an array, find the VALUE of the largest element in the array.
* Once you find it, build a String sentence with the following format:
*
* "For the array [20, 10, 5, 90, 7], the largest value 90 can be found at index 3"
*
*
* @param arr non-empty, non null
* @return a string of the format above.
*/
public static String selectLargest(int[] arr)
{
// TODO: Need to complete.
return "42";
}
/**
* Given an array, and two locations, you will swap the values of those two
* locations. If the x and y parameters represent invalid indexes, then no changes
* will be made to the arr array.
*
* @param arr not null, non-empty.
* @param x
* could be negative or too large
* @param y
* could be negative or too large
*/
public static void swapEmIn1DArray(int[] arr, int x, int y)
{
//first check if the indexes are valid.
//Java subscripts can not be negative nor larger than the length.
//TODO: Finish
//if either of the indexes are valid, then do nothing.
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
