Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1a. Write a function named hasFinalLetter that takes two parameters 1. s

ID: 3585566 • Letter: P

Question

Problem 1a. Write a function named hasFinalLetter that takes two parameters 1. strList, a list of non-empty strings letters, a string of upper and/or lower case letters 2. The function hasFinalLetter should create and return a list of all the strings in strList that end with a letter in letters. Problem 1b. Create three test cases, each consisting of a list of non-empty strings and a string of upper and/or lower case letters, for your function in Problem 1a. One of these tests should return the empty list. For each test case write two assignment statements and a function call that pass the test arguments to your function. Problem 2a. Write a function named isDivisible that takes two parameters 1. 2. maxlnt, an integer twolnts, a tuple of two integers The function isDivisible should create and return a list of all the int's in the range from 0 to maxint (not including maxint) that are divisible of both int's in twolnts Problem 2b. Create three test cases, each consisting of a value for maxlnt and a value for twolnts, for your function in Problem 2a. One of these tests should return the empty list. For each test case write two assignment statements and a function call that pass the test arguments to your function.

Explanation / Answer

import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.io.*;

public class Main {
public static void main(String args[]) {
  
List<String> l = new ArrayList<>();
l.add("my name");
l.add("gg kkl");
hasFinalLetter(l,"e");
  
  
List<String> l1 = new ArrayList<>();
l1.add("my name");
l1.add("gg kkl");
hasFinalLetter(l1,"E");
  
List<String> l2 = new ArrayList<>();
l2.add("my name");
l2.add("gg kkl");
hasFinalLetter(l2,"z");
  
  
}
  
class string{
String s;
}

public static <string> List<String> hasFinalLetter(List<String> st, String a) {
a = a.toLowerCase();
int c=0;
List<String> list = new ArrayList<>();
for(int i=0; i< st.size(); i++){
String s = st.get(i);
String p = s.substring(s.length()-1);
if (a.equals(p)){
list.add(st.get(i));
System.out.println(st.get(i));
c++;

}
  
  
}
if (c ==0){
System.out.println("This list is empty");
}
  
return list;
}
  
  
}