Create a map using the Java map collection. The map should have 4 entries representing students. Each entry should have a unique student ID for the key and a student name for the element value. The map content can be coded in directly, you do not have to allow a user to enter the map data. Your program will display both the key and the value of each element.

Answers

Answer 1

Answer:

In Java:

import java.util.*;  

public class Main{

   public static void main(String[] args) {

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

       students.put("STUD1", "Student 1 Name");

       students.put("STUD2", "Student 2 Name");

       students.put("STUD3", "Student 3 Name");

       students.put("STUD4", "Student 4 Name");

       for(Map.Entry m:students.entrySet()){  

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

}}

Explanation:

This creates the map named students

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

The next four lines populates the map with the ID and name of the 4 students

       students.put("STUD1", "Student 1 Name");

       students.put("STUD2", "Student 2 Name");

       students.put("STUD3", "Student 3 Name");

       students.put("STUD4", "Student 4 Name");

This iterates through the map

       for(Map.Entry m:students.entrySet()){  

This prints the details of each student

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


Related Questions

Suppose a byte-addressable computer using set-associative cache has 2 16 bytes of main memory and a cache size of 32 blocks and each cache block contains 8 bytes. a) If this cache is 2-way set associative, what is the format of a memory address as seen by the cache; that is, what are the size of the tag, set, and offset fields

Answers

Answer:

Following are the responses to these question:

Explanation:

The cache size is 2n words whenever the address bit number is n then So, because cache size is 216 words, its number of address bits required for that  cache is 16 because the recollection is relational 2, there is 2 type for each set. Its cache has 32 blocks, so overall sets are as follows:

[tex]\text{Total Number of sets raluired}= \frac{\text{Number of blocks}}{Associativity}[/tex]

                                               [tex]=\frac{32}{2}\\\\ =16\\\\= 2^4 \ sets[/tex]

The set bits required also are 4. Therefore.

Every other block has 8 words, 23 words, so the field of the word requires 3 bits.

For both the tag field, the remaining portion bits are essential. The bytes in the tag field are calculated as follows:

Bits number in the field tag =Address Bits Total number-Set bits number number-Number of bits of words

=16-4-3

= 9 bit

The number of bits inside the individual fields is therefore as follows:

Tag field: 8 bits Tag field

Fieldset: 4 bits

Field Word:3 bits

Other Questions
20% of 49 is?NEED HELP Please help Im in the middle of a math test and Im very confused give advice to young job seekers on which strategies they can follow if they experience rejection while job hunting The Vatican has to be guarded 24 hours a day. Fifteen Swiss Guards are ordered to split each day's guard duty equally. How long will each Swiss Guard spend on guard duty in one day? Record your answer in hours. Each guard works _____ hours a day. * Someone who has been continuously teased about ones appearance may develop an eating disorder. Please select the best answer from the choices provided T or F i need all of these Imagine you are on a ship in the middle of the ocean . . . What do the sounds make you feel? The sun is:HINT: THERE IS ONLY ONE ANSWER I WILL GIVE BRAINLIEST iF CORRECT 1.the center of the Milky Way galaxy2.made mostly of hydrogen and helium3.the brightest star in the galaxy4.the largest star in the galaxy READ CAREFULLY! - 50 students were randomly sampled and asked if they preferred Coke or Pepsi. 12 preferred Pepsi. If there are 779 students in the school, you would expect ______ students in the entire school to prefer Coke. Enter an answer rounded to the nearest whole number. As the economic prosperity of the 1990s decreased, what changes would one expect in the design of houses? find the general solution and find the specific solutions over the interval [0,4pi]cos(alpha + pi/3) = (sqrt(3))/2 What is the run in the red triangle below? Note the direction of the arrow. 4.B.83How much must be deposited today into the following account in order to have get 35,000 in 5 YearsAn account with monthly compounding and an APR of 4%should be deposited today.(Do not round until the final answer. Then round to the nearest cent as needed) What are the various types of taxes that individuals have to pay in the United States? Bernard is _____ to headaches. Whatever he has to study, his head starts to pound A. perceptive B. suceptible C. profound D infinite What is the exact value of the trigonometric function?(4 pts)cos(600) PLEASE HELP! WILL GIVE BRAINLIEST!How do I format a DBQ Essay? one is due about the effects of the end of world war one and I don't know how my layout should be.Thank you !!!!!!!!!!!!!!!! After the collision, car 1 has a final velocity of 6m/s south. What is the final velocity of car2?a) 35m/s northb) 35m/s southc) 81 m/s northd) 81 m/s south Kieran is going to the florist to buy foxgloves and orchids. The foxgloves can only be purchased in groups of 12 and the orchids can only be purchased in groups of 25. If Kieran wants to buy the same amount of foxgloves and orchids, then what is the lowest quantity of foxgloves that Kieran can buy? pls answer ASAP HELP PLZ DUE RN BRAINIEST TO WHOEVER RIGHT