Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. package meetodid;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8.  
  9. /**
  10. *
  11. */
  12.  
  13. /**
  14. * @author Martin
  15. *
  16. */
  17. public class KytuseHinnad {
  18. public static String[][] kytuseHind() {
  19.  
  20. String[][] hinnad = new String[5][7];
  21. URL html = null;
  22. int i = 0;
  23. String tekstEnneHindaHTMLis95 = "<td align=\"center\">95</td>";
  24. String tekstEnneHindaHTMLis98 = "<td align=\"center\">98</td>";
  25. String tekstEnneHindaHTMLisDiisel = "<td align=\"center\">Diisel</td>";
  26.  
  27. try {
  28.  
  29. html = new URL("http://www.1181.ee/kytusehinnad/Area/1");
  30. } catch (MalformedURLException e) {
  31. System.out.println("URL-iga mingi jama...");
  32. e.printStackTrace();
  33. }
  34. BufferedReader in = null;
  35. try {
  36. in = new BufferedReader(new InputStreamReader(html.openStream()));
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40.  
  41. String sisendiRida;
  42. try {
  43. while ((sisendiRida = in.readLine()) != null) {
  44. if (sisendiRida.contains(tekstEnneHindaHTMLis95)) {
  45.  
  46. while (sisendiRida.contains("</tr>") == false) {
  47. if (i < 7) {
  48. hinnad[0][i] = sisendiRida.replaceAll(
  49. "[a-zA-Z<->=/:;\" ]", "").replaceAll("-",
  50. "");
  51. i = i + 1;
  52. } else {
  53. continue;
  54. }
  55. }
  56. } else if (sisendiRida.contains(tekstEnneHindaHTMLis98)) {
  57. i = 0;
  58. while (sisendiRida.contains("</tr>") == false) {
  59. if (i < 7) {
  60. hinnad[1][i] = sisendiRida.replaceAll(
  61. "[a-zA-Z<->=/:;\" ]", "").replaceAll("-",
  62. "");
  63. i = i + 1;
  64. } else {
  65. continue;
  66. }
  67. }
  68. } else if (sisendiRida.contains(tekstEnneHindaHTMLisDiisel)) {
  69. i = 0;
  70. if (i < 7) {
  71. while (sisendiRida.contains("</tr>") == false) {
  72. hinnad[2][i] = sisendiRida.replaceAll(
  73. "[a-zA-Z<->=/:;\" ]", "").replaceAll("-",
  74. "");
  75. i = i + 1;
  76. }
  77. } else {
  78. continue;
  79. }
  80. } else {
  81. continue;
  82. }
  83. }
  84. } catch (IOException e) {
  85. e.printStackTrace();
  86. }
  87.  
  88. try {
  89. in.close();
  90. } catch (IOException e) {
  91. e.printStackTrace();
  92. }
  93.  
  94. return hinnad;
  95.  
  96. }
  97.  
  98. static String hindadeListike[][] = kytuseHind();
  99.  
  100. public static String euroOil95() {
  101. return hindadeListike[0][2];
  102. }
  103.  
  104. public static String euroOil98() {
  105. return hindadeListike[1][2];
  106.  
  107. }
  108.  
  109. public static String euroOilDiisel() {
  110. return hindadeListike[2][2];
  111.  
  112. }
  113.  
  114. public static String alexela95() {
  115. return hindadeListike[0][3];
  116.  
  117. }
  118.  
  119. public static String alexela98() {
  120. return hindadeListike[1][3];
  121.  
  122. }
  123.  
  124. public static String alexelaDiisel() {
  125. return hindadeListike[2][3];
  126.  
  127. }
  128.  
  129. public static String neste95() {
  130. return hindadeListike[0][4];
  131.  
  132. }
  133.  
  134. public static String neste98() {
  135. return hindadeListike[1][4];
  136.  
  137. }
  138.  
  139. public static String nesteDiisel() {
  140. return hindadeListike[2][4];
  141.  
  142. }
  143.  
  144. public static String olerex95() {
  145. return hindadeListike[0][5];
  146.  
  147. }
  148.  
  149. public static String olerex98() {
  150. return hindadeListike[1][5];
  151.  
  152. }
  153.  
  154. public static String olerexDiisel() {
  155. return hindadeListike[2][5];
  156.  
  157. }
  158.  
  159. public static String statoil95() {
  160. return hindadeListike[0][6];
  161.  
  162. }
  163.  
  164. public static String statoil98() {
  165. return hindadeListike[1][6];
  166. }
  167.  
  168. public static String statoilDiisel() {
  169. return hindadeListike[2][6];
  170.  
  171. }
  172.  
  173. public static void main(String[] args) {
  174. System.out.println(statoilDiisel());
  175. }
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement