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
PYTHON
Korvikt [17]

Answer:

import random

print("Hello! I have a random number from 1 to 100! It is your job to try and guess it!")

number = random.randint(1,101)

guess = int(input("start to guess: "))

num_guesses = 1

while guess != number:

   if guess > number:

       print("lower")

       guess = int(input("try again: "))

       num_guesses +=1

   elif guess < number:

       print ("higher")

       guess = int(input("start to guess: "))

       num_guesses +=1

print("congrats it took you", num_guesses, "tries")

Explanation:

6 0
2 years ago
What is search engine
koban [17]
Search engine is a software to help find you results over the internet.

Examples of search engines are: Google, Safari, Yahoo etc.
4 0
3 years ago
Read 2 more answers
You can join tables by using a condition in the ____ clause.​
andre [41]
You can join tables by using a condition in the "where" clause.
4 0
3 years ago
4.2.5 codehs text messages answer
N76 [4]

Answer:

public class TextMessage

{

   private String message;

   private String sender;

   private String receiver;

   

   public TextMessage(String from, String to, String theMessage)

   {

       sender = from;

       receiver = to;

       message = theMessage;

   }

   

   public String toString()

   {

       return sender + " texted " + receiver + ": " + message;

   }

}

4 0
2 years ago
Extend the class linkedListType by adding the following operations: Write a function that returns the info of the kth element of
WINSTONCH [101]

Answer:

Explanation:

The following code is written in Java. Both functions traverse the linkedlist, until it reaches the desired index and either returns that value or deletes it. If no value is found the function terminates.

public int GetNth(int index)

       {

       Node current = head;

       int count = 0;

       while (current != null)

       {

       if (count == index)

       return current.data;

       count++;

       current = current.next;

       }

       assert (false);

       return 0;

       }

public int removeNth(int index)

       {

       Node current = head;

       int count = 0;

       while (current != null)

       {

       if (count == index)

       return current.remove;

       count++;

       current = current.next;

       }

       assert (false);

       return 0;

       }

6 0
3 years ago
Other questions:
  • Ben buys an Olympus E-PL2 from Sony which starts malfunctioning. When he opts for an exchange, the customer representative says
    11·1 answer
  • Cryptolocker is an example of what type of malware?
    11·1 answer
  • True or False, PDF documents have many benefits, but their main disadvantage is that the formatting of their text and graphic el
    15·1 answer
  • PLEASE HELP<br><br><br> i’m doing a internet safety brochure. what is a good hook ?!
    14·1 answer
  • What mass of nh3 can be made from 35g of n2?
    14·1 answer
  • At age 16 Cheyanne just got her drivers license
    5·2 answers
  • Its a zoom call
    7·1 answer
  • Retraining is required at intervals of ___ or less.
    10·1 answer
  • Whats the formatting of a letter to the editor?​
    12·1 answer
  • Heeeeeeeeeeeeeeeeeeeeeeeeelp pat.2
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!