Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java In the creation of Middle Earth, Eru Ilvatar created the Ainur, who were divided into the Valar and the Maiar. The following are the

java

In the creation of Middle Earth, Eru Ilvatar created the Ainur, who were divided into the Valar and the Maiar. The following are the names of the members of each group:

  • Valar: Manw, Ulmo, Aul, Orom, Mandos, Lrien, Tulkas, Varda, Yavanna, Nienna, Est, Vair, Vna, and Nessa
  • Maiar: Arien, Aiwendil (Radagast), Alatar, Curumo (Saruman), Enw, Durin's Bane, Gothmog, Ilmar, Mairon (Sauron), Melian, Olrin (Gandalf), Oss, Pallando, Salmar, Tilion, and Uinen

We can represent this hierarchy using arrays and Maps:

image text in transcribedimage text in transcribedTASK: Write a public static method called printHierarchy that has one parameter of type Map called hierarchy. For each key in hierarchy, it should print a list like the following (using the example above) without returning anything:

image text in transcribedimage text in transcribedimage text in transcribed

// create a String[] to store the Valar String[] valar = { "Manwe", "Ulmo", "Aule", "Orome", "Mandos", "Lorien", "Tulkas", "Varda", "Yavanna" "Nienna", "Este", "Vaire", "Vana", "Nessa" }; - // create a String[] to store the Maiar String[] maiar = { "Arien", "Aiwendil (Radagast)", "Alatar", "Curumo (Saruman)", "Eonwe" "Durin's Bane", "Gothmog", "Ilmare", "Mairon (Sauron)", "Melian" "Olorin (Gandalf)", "Osse", "Pallando", "Salmar", "Tilion", "Uinen" }; // create a HashMap to store the hierarchy Map ainur = new HashMap(); ainur.put("Valar", valar); ainur.put("Maiar", maiar); * Valar - Manwe Ulmo - Aule Orome - Mandos - Lorien - Tulkas - Varda - Yavanna - Nienna Este - Vaire - Vana - Nessa Maiar - Arien - Aiwendil (Radagast) - Alatar - Curumo (Saruman) Eonwe Durin's Bane - Gothmog Ilmare - Mairon (Sauron) - Melian Olorin (Gandalf) Osse - Pallando - Salmar - Tilion - Uinen Sample Input: Valar, Maiar Manwe, Ulmo, Aule, Orome, Mandos, Lorien, Tulkas, Varda, Yavanna, Nienna, Este, Vaire, Vana, Nessa Arien, Aiwendil (Radagast), Alatar, Curumo (Saruman), Eonwe, Durin's Bane, Gothmog, Ilmare, Mairon (Sauron), Melian, Olorin (Gandalf), Osse, Pallando, Salmar, Tilion, Vinen Sample Output: * Valar - Manwe - Ulmo - Aule - Orome - Mandos - Lorien - Tulkas - Varda - Yavanna - Nienna - Este - Vaire - Vana - Nessa * Maiar - Arien - Aiwendil (Radagast) * Maiar - Arien - Aiwendil (Radagast) - Alatar - Curumo (Saruman) - Eonwe - Durin's Bane - Gothmog - Ilmare - Mairon (Sauron) - Melian - Olorin (Gandalf) - Osse - Pallando - Salmar - Tilion - Vinen

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions