Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package ontarioMap;
  2.  
  3. import postalCodePkg.PostalCodeEntry;
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.nio.charset.StandardCharsets;
  8. import java.nio.file.Files;
  9. import java.nio.file.Path;
  10. import java.nio.file.Paths;
  11.  
  12. /**
  13. * File name: Ghanem.Mishari.Assignment4
  14. * @author: Mishari Ghanem
  15. * Course: CST8284-531
  16. * Term: Winter2019
  17. * Assignment: Assignment4
  18. * Date: 4/10/2019 Purpose: Storing the data in a Map, then retrieve elements from the Map
  19. */
  20.  
  21. public class OntarioMapTest {
  22.  
  23. /**
  24. * main method
  25. *
  26. * @param args args
  27. */
  28. public static void main(String[] args) {
  29. Path file = Paths.get("./ottawa_postal_codes.csv");
  30. OntarioMap maps = new OntarioMap();
  31. BufferedReader reader;
  32.  
  33. try {
  34. reader = Files.newBufferedReader(file, StandardCharsets.UTF_8);
  35. String line;
  36. while ((line = reader.readLine()) != null) {
  37. String[] address = line.split(",");
  38. maps.addToMap(address[0], address[1], address[2], address[3], address[4]);
  39. }
  40. } catch (IOException e) {
  41. e.printStackTrace();
  42. }
  43.  
  44. for (int i = 0; i < 10; i++) {
  45. String rand = PostalCodeEntry.getRandomPrefix();
  46. PostalCodeEntry code = maps.retrievePostalCode(rand);
  47. System.out.printf("Retrieving: %s\n", rand);
  48. if (code != null) {
  49. System.out.printf("\t%s\n", code);
  50. } else {
  51. System.out.printf("\tNOT found\n");
  52. }
  53. }
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement