Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6. Address s1 = new Address();
  7. s1.function1("Россия, Москва, Москва, Нижегородская, 70, 1, 19");
  8. System.out.println("Адрес 1!\n" + s1.toString());
  9.  
  10. Address s2 = new Address();
  11. s2.function2("Россия. Москва. Москва. Калитниковская. 51. 2. 76");
  12. System.out.println("Адрес 2!\n" + s2.toString());
  13.  
  14. Address s3 = new Address();
  15. s3.function2("Украина; Чернигов; Чернигов; Глинки; 23; 1; 7");
  16. System.out.println("Адрес 3!\n" + s3.toString());
  17.  
  18. Address s4 = new Address();
  19. s4.function2("Беларусь-Минск-Минск-Абрикосовая-16-2-45");
  20. System.out.println("Адрес 4!\n" + s4.toString());
  21. }
  22. }
  23.  
  24. package com.company;
  25.  
  26. import java.util.StringTokenizer;
  27.  
  28. public class Address {
  29. private String country;
  30. private String region;
  31. private String town;
  32. private String street;
  33. private String house;
  34. private String building;
  35. private String apartment;
  36.  
  37. public void function1 (String s) {
  38. String[] arr = s.split(", ", 7);
  39.  
  40. country = arr[0];
  41. region = arr[1];
  42. town = arr[2];
  43. street = arr[3];
  44. house = arr[4];
  45. building = arr[5];
  46. apartment = arr[6];
  47. }
  48.  
  49. public void function2 (String s) {
  50. StringTokenizer st = new StringTokenizer(s, " .,;-");
  51. while(st.hasMoreTokens()) {
  52. country = st.nextToken();
  53. region = st.nextToken();
  54. town = st.nextToken();
  55. street = st.nextToken();
  56. house = st.nextToken();
  57. building = st.nextToken();
  58. apartment = st.nextToken();
  59. }
  60. }
  61.  
  62. @Override
  63. public String toString() {
  64. return "Страна: " +country + "\nРегион: " + region +
  65. "\nГород: " + town + "\nУлица: " + street + "\nДом: " + house +
  66. "\nКорпус: " + building + "\nКвартира: " + apartment + "\n";
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement