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

* q2: Write a public static method named q2 that takes an ArrayList of type Char

ID: 3706805 • Letter: #

Question

* q2: Write a public static method named q2 that takes an ArrayList of type Character and * returns a char. This method returns the char that comes first * alphabetically/lexicographically (case sensitive ordering) from the values of the input *(hint: In java, chars are represented as ints that preserve this ordering. You can use) q3: Write a public static method named q3 that takes an ArrayList of type String and *returns an int. This method returns the number of times* a most significant value appears * in the data where significant is defined as the String that comes first * alphabetically/lexicographically (case sensitive ordering) from the values of the input *(hint: Use the compareTo method in the String class) q4: Write a public static method named q4 that takes a HashMap of type String to Character * and returns a String. This method returns the *key mapping to*the char that comes last * alphabetically/lexicographically (case sensitive ordering) from the values of the input * (hint: In Java, chars are represented as ints that preserve this ordering. You can use * and >) *q5: Write a public static method named q5 that takes an ArrayList of Doubles as a * parameter and returns an int. This method returns the index of the first value in the * input that is in the range (-5.55,-2.13) and returns -1 if the input contains no values *in this range

Explanation / Answer

Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

public static char q2(ArrayList<Character> chars) {

char ch = Character.MAX_VALUE;

int chVal = (int) ch;

for (int i = 0; i < chars.size(); i++) {

if ((int) chars.get(i) < chVal) {

ch = chars.get(i);

chVal = (int) ch;

}

}

return ch;

}

public static int q3(ArrayList<String> strings) {

String mostSignificant = strings.get(0);

int count = 0;

for (int i = 0; i < strings.size(); i++) {

if (strings.get(i).compareTo(mostSignificant) < 0) {

mostSignificant = strings.get(i);

count = 1;

} else if (strings.get(i).compareTo(mostSignificant) == 0) {

count++;

}

}

return count;

}

public static String q4(HashMap<String, Character> mp) {

Iterator<Entry<String, Character>> it = mp.entrySet().iterator();

if (it.hasNext()) {

Map.Entry<String, Character> pair = (Map.Entry<String, Character>) it.next();

String lowes = pair.getKey();

Character highChar = pair.getValue();

while (it.hasNext()) {

pair = (Map.Entry<String, Character>) it.next();

if (pair.getValue() > highChar) {

highChar = pair.getValue();

lowes = pair.getKey();

}

}

return lowes;

} else {

return null;

}

}

public static int q5(ArrayList<Double> doubles) {

for (int i = 0; i < doubles.size(); i++) {

if ((doubles.get(i) > -5.55) && (doubles.get(i) < -2.13)) {

return i;

}

}

return -1;

}