1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bas_tet [7]
2 years ago
12

Consider the following client class:import java.util.Collection;import java.util.Collections;import java.util.HashMap;import jav

a.util.Map;import java.util.Set;public class PresidentsMain { public static void main(String[] args) { Map PresidentsOfTheUnitedStates = new HashMap(); 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;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 Entry : InMap.entrySet()) Implement a method PrintValues, that prints all values for a given map (use map’s values() function). Test the implementation on PresidentsOfTheUnitedStates map.Implement a method PrintKeys, that prints all keys for a given map (use map’s keySet() function). Test the implementation on PresidentsOfTheUnitedStates map.
Computers and Technology
1 answer:
Lesechka [4]2 years ago
3 0

Answer:

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 filterMapByValue(Map<String,String> inMap, String targetValue){

           for (Map.Entry<String,String> entry : inMap.entrySet()){

                 if(targetValue.equals(entry.getValue())){

                       System.out.println(entry.getKey()+" - "+entry.getValue());

                 }

           }

     }

     public static void printValues(Map<String,String> map){

           for(String value : map.values()){

                 System.out.println(value);

           }

     }

     public static void printKeys(Map<String,String> map){

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

                 System.out.println(key);

           }

     }

     public static void main(String[] args) {

           Map<String, String> PresidentsOfTheUnitedStates = new HashMap<String, String>();

           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");

           System.out.println("Presidents of Democratic-Republican party: ");

           filterMapByValue(PresidentsOfTheUnitedStates,"Democratic-Republican");

           System.out.println();

           System.out.println("Keys: ");

           printKeys(PresidentsOfTheUnitedStates);

           System.out.println();

           System.out.println("Values: ");

           printValues(PresidentsOfTheUnitedStates);

      }

}

Explanation:

See the code above

You might be interested in
How are you doing this fine morning <br><br> hi
notka56 [123]
It's evening................∆
6 0
3 years ago
Read 2 more answers
The query [windows], English (US) has two dominant interpretations: the operating system and the windows in a home
Nadusha1986 [10]

Answer:

True

Explanation:

When the word windows is google, there are two basic interpretations: operating system and the windows in a home. This is the two dominant interpretation can be given to the word windows when queried.

6 0
3 years ago
The highlighted items in the webpage are called …………………………………..
seraphim [82]

Answer:

highlighted items in webpage are called links.

5 0
3 years ago
Pls can anyone be so kind and answer this question.....i need the answer urgently
mixas84 [53]

Answer:

so u have to be smaet

Explanation:

8 0
2 years ago
To create a query, users can either type a query using sql or, more commonly, use the query tools built into the dbms (such as a
sattari [20]
The answer is : wizard
8 0
1 year ago
Other questions:
  • Users of an extranet can access a company or organization’s entire intranet
    8·2 answers
  • I need help to find out what is wrong with this program and my variable, "exponent" comes out as 0 in the output instead of the
    14·1 answer
  • An email address is made up of all of the following parts except
    13·2 answers
  • Complex communication skills will probably never be outsourced to a computer because they require the human touch.
    8·1 answer
  • When 2 or more computers are connected it is called?
    14·1 answer
  • Why would an online survey of 2,000 visitors to your college’s Web site be of little use in assessing the neighboring community’
    7·1 answer
  • ​________________________ are the main forms of direct and digital marketing. A. Mobile​ marketing, social media​ marketing, and
    5·1 answer
  • Create a list with 5 numbers and find the smallest and largest number in the list and also the sum and product of the numbers in
    9·1 answer
  • How can we avoid falling victim to a phishing or pharming scheme
    14·1 answer
  • Both IT professionals and governments must apply ethical principles to certify that emerging technologies are to society.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!