Advertisement
evgenko

Untitled

Sep 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.io.*;
  5. import java.nio.charset.Charset;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.Scanner;
  10.  
  11. public class Main
  12. {
  13.     public static void aasd(String a){
  14.  
  15.  
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.         Scanner read = new Scanner(System.in);
  20.         String workingDir = System.getProperty("user.dir");
  21.         String filename;
  22.         String line;
  23.         Map<String,String> city_country = new HashMap<String,String>();
  24.         boolean a = true;
  25.  
  26.         System.out.println("Current dir: "+workingDir);
  27.         filename = read.next();
  28.  
  29.         try (
  30.                 InputStream fis = new FileInputStream(filename);
  31.                 InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
  32.                 BufferedReader br = new BufferedReader(isr);
  33.         ) {
  34.             while ((line = br.readLine()) != null) {
  35.  
  36.                 if (a) {
  37.                     if (line.contains(",")) {
  38.                         String[] strings = line.split(",");
  39.                         city_country.put(strings[0], strings[1]);
  40.                     }
  41.                 }
  42.  
  43.             }
  44.         } catch (FileNotFoundException e) {
  45.             e.printStackTrace();
  46.         } catch (IOException e) {
  47.             e.printStackTrace();
  48.         }
  49.  
  50.  
  51.  
  52.  
  53.         a=true;
  54.         while (a){
  55.             System.out.print("Write the name of the city or write 'STOP' for end: ");
  56.             String c =read.next();
  57.             if ((c).equals("STOP"))
  58.                 a=false;
  59.             if(a){
  60.                 if ((city_country.get(c)!=(null)))
  61.                     System.out.println("Country: "+city_country.get(c));
  62.                 else System.out.println("Country doesn't exist");
  63.             }
  64.         }
  65.  
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement