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]
3 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]3 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
A car holds 16 gallons of gasoline and can travel 312 miles before refueling. Write aC++ program that calculates the number of m
IgorC [24]

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables Declaration and initialization

   int no_gallon=16;

   int dis=312;

   // find the miles per gallon

   double mile_gallon=dis/double(no_gallon);

   // print the results

   cout<<"number of gallons: "<<no_gallon<<endl;

   cout<<"distance travel before refueling: "<<dis<<endl;

   cout<<"miles per gallon is: "<<mile_gallon<<endl;

return 0;

}

Explanation:

Declare and initialize the number of gallon and distance travel without refueling. Calculate the miles per gallon by dividing distance with number of gallons.Then print the results.

Output:

number of gallons: 16

distance travel before refueling: 312

miles per gallon is: 19.5

6 0
3 years ago
What is a browser cookie?
nikitadnepr [17]

B) its a small peice of data that tracks your preferances on diffrent websites

Have a great day !

6 0
3 years ago
Read 2 more answers
What natural resources fueled industrialization in the united states?
hichkok12 [17]

Natural Resources that fueled American Industrialization

 

<span>1. Iron ore: Used to create steel and pig iron.  Used for railroad ties, bridges, buildings.</span>

 

2. Coal: with the invention of the steam engine, coal replaced wood in fueling the steam engine and machinery used in various industries such as the steel industry.

 

<span>3. Oil: The ability to use a steam engine for oil drilling started an oil boom in the United States.  It helped with the creation of a Petroleum-refining industry.  Transformed oil into Kerosene and later gasoline for the automobile</span>

 

Lumber: Used to fuel the steam engines that were used on trains, steamboats, and in industry for the new machines being invented that ran on steam.

<span> </span>

5 0
3 years ago
True/False: Audio menus can be useful when one's hands and eyes are busy, or to assist vision-impaired users. With audio menus,
Aloiza [94]

Answer:

I believe the answer is true

5 0
3 years ago
How do you use a Hard Drive
Ray Of Light [21]
Plug it into pc and wahlah
3 0
3 years ago
Read 2 more answers
Other questions:
  • The class Date has a single constructor that accepts the integer value: a month- (1 for January through 12 for December), a day
    13·1 answer
  • On the food inventory worksheet, enter a function in cell G1 that counts the number of Food Items. What formula would i use!? Th
    5·1 answer
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • A software programâs _________ indicates what can legally be done with that program.]
    5·1 answer
  • What are the coordinates of (3 comma space 8 )relative to the basis open curly brackets space (1 comma space 1 )comma space (0 c
    15·1 answer
  • Why are medical related professions and human resources important? ​
    8·1 answer
  • Juhfvehrfwhedfhwkefhkujhiuyuiyuiyiyh
    6·1 answer
  • If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
    10·1 answer
  • Which of the following is an example of machine learning?
    5·1 answer
  • each data mining technique has its advantages and limitations. which data mining technique mimics the neural structure of the br
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!