I continue to submit incorrect UML class diagrams with my code. I do not know why I can not get them correct. Please hel
Posted: Fri May 20, 2022 12:41 pm
I continue to submit incorrect UML class diagrams with my code.
I do not know why I can not get them correct. Please help with a
UML class diagram for the code below? Thank you !
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class HashMapDemo {
public static void main(String args[]){
HashMap countriesMap = new HashMap();
countriesMap.put(1, "USA");
countriesMap.put(2, "Mexico");
countriesMap.put(5, "France ");
countriesMap.put(21, "India");
countriesMap.put(49, "Australia");
// continue adding 5 more key-value pairs
countriesMap.put(60, "Finland");
countriesMap.put(51, "Egypt");
countriesMap.put(12, "Bahamas");
countriesMap.put(130,"Norway");
countriesMap.put(26, "Bulgaria");
// Display the content using Iterator.
Iterator> it = countriesMap.entrySet().iterator();
while (it.hasNext())
{
//gets next entry (integer, String pair) using iterator
Map.Entry entry = it.next();
//displaying key and value of entry.
System.out.println(entry.getKey() + "\t" + entry.getValue());
}
// get and display the country based on the key value : accept the
key value = 49
int key=49;
System.out.println("\nCountry with the key value of 49 = "
+countriesMap.get(key));
// remove Australia and Mexico from the countriesMap
countriesMap.remove(2);
countriesMap.remove(49);
// determine and display how many countries are left in the HashMap
using size() method
System.out.println("\nCountries left after removing Australia and
Mexico: "+countriesMap.size());
// Display the content of modified countriesMap
System.out.println(countriesMap);
// remove all mapping entries from the countriesMap and display the
resulting content of the HashMap
countriesMap.clear();
System.out.println("\nMap after removing all mappings:");
System.out.println(countriesMap);
}
}
I do not know why I can not get them correct. Please help with a
UML class diagram for the code below? Thank you !
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class HashMapDemo {
public static void main(String args[]){
HashMap countriesMap = new HashMap();
countriesMap.put(1, "USA");
countriesMap.put(2, "Mexico");
countriesMap.put(5, "France ");
countriesMap.put(21, "India");
countriesMap.put(49, "Australia");
// continue adding 5 more key-value pairs
countriesMap.put(60, "Finland");
countriesMap.put(51, "Egypt");
countriesMap.put(12, "Bahamas");
countriesMap.put(130,"Norway");
countriesMap.put(26, "Bulgaria");
// Display the content using Iterator.
Iterator> it = countriesMap.entrySet().iterator();
while (it.hasNext())
{
//gets next entry (integer, String pair) using iterator
Map.Entry entry = it.next();
//displaying key and value of entry.
System.out.println(entry.getKey() + "\t" + entry.getValue());
}
// get and display the country based on the key value : accept the
key value = 49
int key=49;
System.out.println("\nCountry with the key value of 49 = "
+countriesMap.get(key));
// remove Australia and Mexico from the countriesMap
countriesMap.remove(2);
countriesMap.remove(49);
// determine and display how many countries are left in the HashMap
using size() method
System.out.println("\nCountries left after removing Australia and
Mexico: "+countriesMap.size());
// Display the content of modified countriesMap
System.out.println(countriesMap);
// remove all mapping entries from the countriesMap and display the
resulting content of the HashMap
countriesMap.clear();
System.out.println("\nMap after removing all mappings:");
System.out.println(countriesMap);
}
}