fryc1906

projekt.adress

Jan 21st, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. package bin;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.URL;
  7. import java.util.Calendar;
  8. import java.util.Scanner;
  9.  
  10. public class AdressMode {
  11. private String name1="",name2="";
  12. private String line1,line2,tempLine;
  13. private Scanner input;
  14. private byte mode=-1;
  15. private int year;
  16. private URL dirURLFile=null;
  17. private int counter=0;
  18. private BufferedReader dirFile=null;
  19.  
  20. public String getLink1(){
  21. name1="http://www.nbp.pl/kursy/xml/"+line1+".xml";
  22. return name1;
  23. }
  24. public String getLink2(){
  25. name2="http://www.nbp.pl/kursy/xml/"+line2+".xml";
  26. return name2;
  27. }
  28.  
  29. public void setMode() throws Exception{
  30. System.out.println("test");
  31. input = new Scanner(System.in);
  32. while(mode<0 ||mode >3){
  33. System.out.println("Wybierz tryb programu");
  34. mode = input.nextByte();
  35. if(mode==1){
  36. System.out.println("Jestem w setMode = 1");
  37. modeNewest();
  38. }
  39. else if(mode==2){
  40. modeCustomDate();
  41. }
  42. else if(mode==3){
  43. modeCustomWrite();
  44. }
  45.  
  46. }
  47.  
  48. }
  49.  
  50.  
  51.  
  52. public void AdressMode(){
  53.  
  54. }
  55.  
  56. private void getCurrentYear(){
  57. year = Calendar.getInstance().get(Calendar.YEAR);
  58. }
  59.  
  60. public void openFileDir() throws Exception{
  61. try{
  62. if(mode==2){
  63. dirURLFile=new URL("http://www.nbp.pl/kursy/xml/dir"+year+".txt");
  64. }
  65. if(mode==1){
  66. dirURLFile=new URL("http://www.nbp.pl/kursy/xml/dir.txt");
  67. }
  68. dirFile = new BufferedReader(new InputStreamReader(dirURLFile.openStream()));
  69. findLastTablesNames();
  70.  
  71. }
  72. finally{
  73. if(dirFile!=null){
  74. dirFile.close();
  75. }
  76. }
  77. }
  78. public void findLastTablesNames() throws Exception{
  79. tempLine=dirFile.readLine();
  80. //System.out.println(name1);
  81. while(tempLine!=null){
  82. if(tempLine.contains("a")){
  83. //System.out.println(name1+name2);
  84. line2=line1;
  85. line1=tempLine;
  86. //System.out.println(name1+name2);
  87. }
  88. tempLine=dirFile.readLine();
  89. System.out.println(line1+" test "+line2);
  90.  
  91. }
  92.  
  93. }
  94. public void findTablesByDate() throws Exception{
  95.  
  96. openFileDir();
  97. tempLine=dirFile.readLine();
  98. }
  99.  
  100. public void modeNewest() throws Exception{
  101. System.out.println("Jestem w modeNewest()");
  102. openFileDir();
  103. tempLine=dirFile.readLine();
  104. while(tempLine!=null){
  105. if(tempLine.contains(name1)&&tempLine.contains("a")){
  106. line1=tempLine;
  107. }
  108. if(tempLine.contains(name1)&&tempLine.contains("a")){
  109. line2=tempLine;
  110. }
  111. tempLine=dirFile.readLine();
  112. }
  113.  
  114.  
  115. }
  116. public void modeCustomDate(){
  117. input = new Scanner(System.in);
  118. System.out.println("Wprowadz date 1 pliku (DDMMYY");
  119. name1=input.nextLine();
  120. System.out.println("Wprowadz date 2 pliku (DDMMYY");
  121. name1=input.nextLine();
  122. }
  123. public void modeCustomWrite(){
  124. input = new Scanner(System.in);
  125. System.out.println("Wprowadz link do pierwszej tabeli:");
  126. name1=input.nextLine();
  127. System.out.println("Wprowadz link do drugiej tabeli:");
  128. name2=input.nextLine();
  129.  
  130. }
  131. }
Add Comment
Please, Sign In to add comment