Question
Here is my assignment: --------------------------------------------------- Consider the following client class: import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; public class PresidentsMain { public
Here is my assignment:
---------------------------------------------------
Consider the following client class:
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class PresidentsMain {
public static void main(String[] args) {
Map
PresidentsOfTheUnitedStates.put("George Washington", "Unaffiliated");
PresidentsOfTheUnitedStates.put("John Adams", "Federalist");
PresidentsOfTheUnitedStates.put("Thomas Jefferson", "Democratic-Republican");
PresidentsOfTheUnitedStates.put("James Madison", "Democratic-Republican");
PresidentsOfTheUnitedStates.put("James Monroe", "Democratic-Republican");
PresidentsOfTheUnitedStates.put("John Quincy Adams", "Democratic-Republican");
PresidentsOfTheUnitedStates.put("Andrew Jackson", "Democratic");
PresidentsOfTheUnitedStates.put("Martin Van Buren", "Democratic");
PresidentsOfTheUnitedStates.put("William Henry Harrison", "Whig");
PresidentsOfTheUnitedStates.put("John Tyler", "Whig");
}
}
}
Extend given client class:
- Implement a static method called FilterMapByValue, that takes 2 parameters:
- Map
InMap; - String TargetValue;
- Map
Method should print out all map elements, for which Value == TargetValue. Test the implementation by filtering PresidentsOfTheUnitedStates map so that only presidents, affiliated with Democratic-Republican party are printed. Note: use the following to iterate over a map:
for (Map.Entry
- Implement a method PrintValues, that prints all values for a given map (use maps values() function). Test the implementation on PresidentsOfTheUnitedStates map.
- Implement a method PrintKeys, that prints all keys for a given map (use maps keySet() function). Test the implementation on PresidentsOfTheUnitedStates map.
------------------------------------------
I got this today and it's due tomorrow. I'm lost in this class and don't understand how to do this :(
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started