Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If I have the method: public static Map pairing(List stringList) { Map map = new HashMap (); for (String str: stringList){ Character key = str.charAt(

If I have the method:

public static Map pairing(List stringList) { Map map = new HashMap<>(); for(String str: stringList){ Character key = str.charAt(0); if (!map.containsKey(key)){ map.put(key, str.charAt(str.length()-1)); } } return map; } 

and the following test cases with their corresponding expected result:

Note: In the following expected results {b=g, c=e} means thereare 2 entries in the resulted map: where first entry has 'b' as the key and 'g' as the value, second entry has 'c' as the key and 'e' as the value.

1.pairing(["code", "bug"])expected result:{b=g, c=e}

2.pairing(["man", "moon", "main"])expected result:{m=n}

3.pairing(["man", "moon", "good", "night"])expected result:{g=d, m=n, n=t}

4.pairing([])expected result:{} . The output is an empty Map.

5.pairing(["are", "codes", "and", "cods"])expected result:{a=d, c=s}

6.pairing(["a", "b"])expected result:{a=a, b=b}

Questions:

a)Which one of the above test cases that will not give you the expected result?

b) If you've been asked to resolve this glitch (bug), what you have to change in method code. Write down your code of the method to fix this glitch (bug).

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

1 The role of banks in the economy

Answered: 1 week ago