Question: |Java] Suppose we are using a HashMap to store information about restaurants and their locations. It maps Points to Restaurant objects. A reminder of the

 |Java] Suppose we are using a HashMap to store information about

|Java] Suppose we are using a HashMap to store information about restaurants and their locations. It maps Points to Restaurant objects. A reminder of the Point class is shown on the code handout. A Restaurant object has a name and other attributes, and also has a mutator called set Name to change the name of the restaurant. You may assume the following code happens sometime before the code snippets given below: Map restMap; [. . . code to initialize and put values in restMap] For each of the following code sequences, give an answer 1, 2, 3, or 4, where these numbers stand for: 1) the code has no effect on the Map (leaves it unchanged) 2) the code invalidates the Map 3) the code modifies, but does not invalidate, the map, but does not work as intended 4) the code works as intended (Note: the intended behavior for each sequence is shown in the inline comments in the code below.) Part A. answer: Restaurant rest - restMap. get (new Point (3, 7) ) ; if (rest != null) { rest. setName ("KFC") ; // change the name of the restaurant at (3, 7) to KFC Part B. answer: // [enhanced for loop below] for (Map. Entry entry : restMap. entrySet () ) { int xLoc = (int) entry.getkey () .getx() ; if (xLoc == 574) // adjust the location of some restaurants: entry . getkey () . translate (3, 0) ; // move to the right by 3 Part C. answer: Restaurant rest - restMap. get (new Point (10, 12) ) ; if (rest != null) rest - new Restaurant ("Mcdonald's", // change the restaurant at (10,12) to Mcdonald's

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!