Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

|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

image text in transcribed
|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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions