Question: [Java] Please fix my wordsEndingIn method. You have to use Arrays.copyOf(). You can't use anything like List or clone(). Implement these methods: public static int

[Java] Please fix my wordsEndingIn method. You have to use Arrays.copyOf(). You can't use anything like List or clone().

Implement these methods:

public static int min(int[] list) Gets the minimum value in the array. You can assume the array has at least one element

public static int min(ArrayList list) Gets the minimum value in the ArrayList as an int. You can assume the ArrayList contains at least one element

public static ArrayList wordsEndingIn(ArrayList list, String letter) Gets an ArrayList of all the words in the given ArrayList that contain the given letter. The comparison is case-insensitive. 'A' and 'a' are counted as the same letter

public static String[] wordsEndingIn(String[] list, String letter) Gets an array of all the words in the given array that contain the given letter. The comparison is case-insensitive. 'A' and 'a' are counted as the same letter. You will need to use Arrays.copyOf() to return an array that contains just the words ending in the letter

[Here's my code and the last method is the problem I'm in]

import java.util.ArrayList; import java.util.Arrays;

/** * Static methods working with arrays and arraylists */ public class StuffAndThings { /** * Get the minimum number in the array * @param list an array to work with * @return min minimum number in the array */ public static int min(int[] list) { int min = list[0]; for(int i = 0; i < list.length; i++) { if(min > list[i]) { min = list[i]; } } return min; } public static int min(ArrayList list) { int min = list.get(0); for(int i = 0; i < list.size(); i++) { if(min > list.get(i)) { min = list.get(i); } } return min; } public static ArrayList wordsEndingIn(ArrayList list, String letter) { ArrayList endsWith = new ArrayList(); for(int i = 0; i < list.size(); i++) { String check = list.get(i).toLowerCase(); if(check.contains(letter.toLowerCase())) { endsWith.add(list.get(i)); } } return endsWith; } public static String[] wordsEndingIn(String[] list, String letter) { String[] str = new String[list.length]; int count = 0; for(int i = 0; i < list.length; i++) { if(!list[i].endsWith(letter)) { str[i] = str[i - 1]; } else { str[i] = list[i]; } count++; } String[] copy = Arrays.copyOf(str, count); return copy;

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!