package com.codegym.task.task08.task0829;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
Software update
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String,String>familes = new HashMap<>();
familes.put("Chicago","Capone");
familes.put("New York City","Rockefeller");
familes.put("Seattle","Gates");
for (Map.Entry<String,String> cityes:familes.entrySet()
) {
System.out.println(cityes.getKey() + "\n" + cityes.getValue());
}
String family = reader.readLine();
for (Map.Entry<String,String> cityes:familes.entrySet()
) {
if(cityes.getKey().equalsIgnoreCase(family)){
System.out.println(cityes.getValue());
}
}
// // List of addresses
// List<String> addresses = new ArrayList<>();
// while (true) {
// String family = reader.readLine();
// if (family.isEmpty()) break;
//
// addresses.add(family);
// }
//
// // Read the house number
// int houseNumber = Integer.parseInt(reader.readLine());
//
// if (0 <= houseNumber && houseNumber < addresses.size()) {
// String familyName = addresses.get(houseNumber);
// System.out.println(familyName);
// }
}
}
MecoS
Level 16
Maybe i didn't understand the question
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
8 December 2019, 16:46
This code has hard coded the example inputs in at lines 21-23. The task requires the user to enter those values instead. Get rid of those lines and code it so that the user can enter them. This is what the program should do:
1) Read in and stores pairs (City, Family) until the user enters an empty/blank string
2) takes in 1 more user input, a city
3) displays the family that is in the city from step #2
+1
MecoS Full Stack Developer at Microsoft
9 December 2019, 11:21
Thanks. Now i understand.
0