Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Prepare an ID card of the continent Antarctica?

Answered: 1 week ago

Question

What do you understand by Mendeleev's periodic table

Answered: 1 week ago