This is a java program. PLEASE WRITE THIS IN JAVA AND FOLLOW ALL THE
INSTRUCTIONS. THERE SHOULD BE A Tester.java class
Objective: Practice using maps. All the methods you write for this should be marked static and
called from the main(..). Note: none of these exercises have you mutate the input map (you will
always be returning a copy of the given map with the requested modifications made).
Note 1: you'll only need put(..), containsKey(..), get(..), and remove(..) for all of these methods
(there are fancier map methods, though I'll leave these to you to look up for research)
Note 2: sample inputs and outputs are included with each method, the ordering of the (key, value)
pairs in the returned map might vary.
Note 3: java prints maps like this: {a=cat, b=dog}
-in our notation, this is: { (a, cat), (b, dog) }
Question 1: bullyReplace (no loops needed for this one)
Write a static method called bullyReplace that takes a Map<String, String> m as a parameter and
returns a Map<String, String>. The method should create a copy of the input map m and return the
copied map with the following changes made:
--> if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the
value "". Basically "b" is a bully, taking the value and replacing it with the empty string.
Some input-output examples:
--> bullyReplace( {("a", "candy"), ("b", "dirt")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy"), ("b", "carrot"), ("c", "meh")
-should return: { ("a", ""), ("b", "candy"), ("c", "meh") }
Here's some starter code for the method to get you going (you'll have similar setup code for the
remaining methods):
Question 2: toppings (no loops needed for this one)
Write a static method named toppings that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
-->if the key "ice cream" is present, set its value to "cherry". In all cases, set the key "bread" to
have the value "butter".
Some examples:
--> toppings( {("ice cream", "peanuts")} )
-should return: { ("bread", "butter"), ("ice cream", "cherry") }
-->toppings( {} )
-should return: { ("bread", "butter") }
-->toppings( {("pancake", "syrup")} )
-should return: {("bread", "butter"), ("pancake", "syrup")}
Question 3: mapShare (no loops needed for this one)
Write a static method named mapShare that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
-->if the key "a" has a value, set the key "b" to have that same value. In all cases remove the key
"c", leaving the rest of the map unchanged.
Some examples:
-->mapShare({("a", "aaa"), ("b", "bbb"), ("c", "ccc")})
-should return: {("a", "aaa"), ("b", "aaa")}
-->mapShare({("b", "xyz"), ("c.
This PowerPoint helps students to consider the concept of infinity.
This is a java program PLEASE WRITE THIS IN JAVA AND FOLLOW.pdf
1. This is a java program. PLEASE WRITE THIS IN JAVA AND FOLLOW ALL THE
INSTRUCTIONS. THERE SHOULD BE A Tester.java class
Objective: Practice using maps. All the methods you write for this should be marked static and
called from the main(..). Note: none of these exercises have you mutate the input map (you will
always be returning a copy of the given map with the requested modifications made).
Note 1: you'll only need put(..), containsKey(..), get(..), and remove(..) for all of these methods
(there are fancier map methods, though I'll leave these to you to look up for research)
Note 2: sample inputs and outputs are included with each method, the ordering of the (key, value)
pairs in the returned map might vary.
Note 3: java prints maps like this: {a=cat, b=dog}
-in our notation, this is: { (a, cat), (b, dog) }
Question 1: bullyReplace (no loops needed for this one)
Write a static method called bullyReplace that takes a Map<String, String> m as a parameter and
returns a Map<String, String>. The method should create a copy of the input map m and return the
copied map with the following changes made:
--> if the key "a" has a value, set the key "b" to have that value, and set the key "a" to have the
value "". Basically "b" is a bully, taking the value and replacing it with the empty string.
Some input-output examples:
--> bullyReplace( {("a", "candy"), ("b", "dirt")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy")} )
--> should return: { ("a", ""), ("b", "candy") }
--> bullyReplace( {("a", "candy"), ("b", "carrot"), ("c", "meh")
-should return: { ("a", ""), ("b", "candy"), ("c", "meh") }
Here's some starter code for the method to get you going (you'll have similar setup code for the
remaining methods):
Question 2: toppings (no loops needed for this one)
Write a static method named toppings that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
-->if the key "ice cream" is present, set its value to "cherry". In all cases, set the key "bread" to
have the value "butter".
Some examples:
--> toppings( {("ice cream", "peanuts")} )
-should return: { ("bread", "butter"), ("ice cream", "cherry") }
-->toppings( {} )
-should return: { ("bread", "butter") }
-->toppings( {("pancake", "syrup")} )
-should return: {("bread", "butter"), ("pancake", "syrup")}
Question 3: mapShare (no loops needed for this one)
Write a static method named mapShare that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
2. map with the following changes made:
-->if the key "a" has a value, set the key "b" to have that same value. In all cases remove the key
"c", leaving the rest of the map unchanged.
Some examples:
-->mapShare({("a", "aaa"), ("b", "bbb"), ("c", "ccc")})
-should return: {("a", "aaa"), ("b", "aaa")}
-->mapShare({("b", "xyz"), ("c", "ccc")})
-should return: {("b", "xyz")}
-->mapShare({("a", "aaa"), ("c", "meh"), ("d", "hi")})
-should return: {("a", "aaa"), ("b", "aaa"), ("d", "hi")}
Question 4: mapAB (no loops needed for this one)
Write a static method named mapAB that takes a Map<String, String> m and returns a
Map<String, String>. The method should create a copy of the input map m and return the copied
map with the following changes made:
--> for this problem the returned map may or may not contain the "a" and "b" keys. If both keys are
present, append their 2 string values together and store the result under the key "ab".
Some examples:
--> mapAB( {("a", "Hi"), ("b", "There")} )
- should return: {("a", "Hi"), ("ab", "HiThere"), ("b", "There")}
--> mapAB( {("a", "Hi")} )
- should return: {("a": "Hi")}
--> mapAB( {("b", "There")} )
- should return: {("b", "There")}
Question 5: wordCount0 (1 loop needed)
Write a static method, wordCount0, that takes a list of strings and returns a Map<String, Integer>
containing a key for every different string in the input list -- always with the value 0.
Some examples:
-->wordCount0(List.of("a", "b", "a", "b"))
-should return: {(a, 0), (b, 0)}
-->wordCount0(List.of("a", "b", "a", "c", "b"))
-should return: {(a, 0), (b, 0), (c, 0)}
Question 6: wordLen (1 loop needed)
Write a static method, wordLen that takes list of strings as a parameter and returns a Map<String,
Integer> containing a key for every string in the input list, mapped to that string's length.
Some examples:
-->wordLen(List.of("a", "bb", "a", "bb"))
-should return: {("a", 1), ("bb", 2)}
-->wordLen(List.of("this", "and", "that", "and"))
-should return: {("this", 4), ("and", 3), ("that", 4)}
-->wordLen(List.of("code", "code", "code", "bug"))
-should return: {("code", 4), ("bug", 3)}
Question 7: wordMultiple (1 loop needed)
3. Given a List<String> as a parameter, this method returns a Map<String, Boolean> where each
different string is a key and its value is true if that string appears 2 or more times in the array.
-->wordMultiple(List.of("a", "b", "a", "c", "b"))
-should return: {("a", true), ("b", true), ("c", false)}
-->wordMultiple(List.of("c", "b", "a"))
-should return: {("a", false), ("b", false), ("c", false)}
-->wordMultiple(List.of("c", "c", "c", "c"))
-should return: {("c", true)}
HERE IS A DOWNABLE FILE THAT WAS INCLUDED IN THE ASSIGNMENT. THIS WAS IN THE
JAVA FILE: