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

Write the output produced when the following methods is passed each of the follo

ID: 3780340 • Letter: W

Question

Write the output produced when the following methods is passed each of the following maps:

public static void mystery(Map<String, String> m) {

Set<String> s = new TreeSet(String);

for (String key : m.keySet()){

if (!m.get(key).equals(key)) {

s.add(m.get(key));

} else {

s.remove(m.get(key));

}

}

System.out.println(s);

}

a. {sheep=wool, house=brick, cast=plaster, wool=wool}

b. {ball=blue, winkie=yellow, corn=yellow, grass=green, emerald=green}

c. {pumpkin=peach, corn =apple, apple=apple, pie=fruit, peach=peach}

d. {lab=ipl, lion=cat, corgi=dog, cat=cat, emu=animal, nyan=cat}

Explanation / Answer

Answers:

a. {sheep=wool, house=brick, cast=plaster, wool=wool} will print [brick, plaster]

b. {ball=blue, winkie=yellow, corn=yellow, grass=green, emerald=green} will print [blue, green, yellow]

c. {pumpkin=peach, corn =apple, apple=apple, pie=fruit, peach=peach} will print [apple, fruit]

d. {lab=ipl, lion=cat, corgi=dog, cat=cat, emu=animal, nyan=cat} will print [animal, cat, dog, ipl]