Guest User

Untitled

a guest
Jun 20th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package realestate;
  7.  
  8. import java.io.*;
  9. import java.util.*;
  10. import java.io.File;
  11. import java.lang.*;
  12.  
  13.  
  14. /**
  15. *
  16. * @author Colin
  17. */
  18. public class Main {
  19.  
  20.  
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) {
  25. // TODO code application logic here
  26. String[] InitialArray;
  27. int[] PropertyID;
  28. String[] PropertyType;
  29. double[] PropertyValue;
  30. double[] CompletePropertyValue;
  31. int[] AgentID;
  32. int counter=0;
  33. int arraySize = 0;
  34. int arraySize2 = 0;
  35.  
  36. System.out.print("Where is the text file located: ");
  37. Scanner input =new Scanner(System.in);
  38. String FileLocation = input.next();
  39. try{
  40. FileInputStream fis2 = new FileInputStream(FileLocation);
  41. DataInputStream dis2 = new DataInputStream(fis2);
  42. BufferedReader br2 = new BufferedReader(new InputStreamReader(dis2));
  43. String Writing;
  44. while((Writing=br2.readLine())!=null){
  45. arraySize++;
  46. }
  47. br2.close();
  48. FileInputStream fis = new FileInputStream(FileLocation);
  49. DataInputStream dis = new DataInputStream(fis);
  50. BufferedReader br = new BufferedReader(new InputStreamReader(dis));
  51. PropertyID = new int[arraySize];
  52. PropertyType = new String[arraySize];
  53. PropertyValue = new double[arraySize];
  54. CompletePropertyValue = new double[arraySize];
  55. AgentID = new int[arraySize];
  56. String Writing2;
  57. int SetCounter=0;
  58. while((Writing2=br.readLine())!=null){
  59. //System.out.print(Writing);
  60. InitialArray = Writing2.split("\\s+");
  61. for (int j = 0; j < InitialArray.length; j++) {
  62. if(j==0)
  63. {
  64. //System.out.println(InitialArray[j]);
  65. PropertyID[SetCounter] = Integer.parseInt(InitialArray[j]);
  66. //System.out.print("Worked");
  67. }
  68. if(j==1)
  69. {
  70. //System.out.println(InitialArray[j]);
  71. PropertyType[SetCounter]=InitialArray[j];
  72. }
  73. if(j==2)
  74. {
  75. //System.out.println(InitialArray[j]);
  76. PropertyValue[SetCounter] = Double.parseDouble(InitialArray[j]);
  77. }
  78. if(j==3)
  79. {
  80. //System.out.println(InitialArray[j]);
  81. AgentID[SetCounter]=Integer.parseInt(InitialArray[j]);
  82. }
  83.  
  84. }
  85. SetCounter++;
  86. }
  87. br.close();
  88. for (int i = 0; i < PropertyType.length; i++) {
  89. PropertyType[i].toUpperCase();
  90. }
  91. Arrays.sort(PropertyType);
  92.  
  93. // int tempcount = 0;
  94. // for(int i : AgentID){
  95. // for(int j : AgentID){
  96. // if(i==j)
  97. // {
  98. // tempcount++;
  99. // }
  100. // }
  101. // }
  102. //
  103. // int tc[]=new int[tempcount];
  104. // String[] LinkedArrays= new String[arraySize];
  105. // for (int i = 0; i < AgentID.length; i++) {
  106. // LinkedArrays[i] = (AgentID[i] + " " + PropertyValue[i]);
  107. // }
  108. // Arrays.sort(LinkedArrays);
  109. // for (int i = 0; i < LinkedArrays.length; i++) {
  110. // String[] TempStringArray = new String[arraySize];
  111. // TempStringArray = LinkedArrays[i].split("\\s+");
  112. // AgentID[i]= Integer.parseInt(TempStringArray[0]);
  113. // PropertyValue[i] = Double.parseDouble(TempStringArray[1]);
  114. // }
  115. // int placeHolder = 0;
  116. // for (int i = 0; i < AgentID.length-1; i++) {
  117. // if(AgentID[i]==AgentID[i++])
  118. // {
  119. // tc[placeHolder] += (PropertyValue[i]+PropertyValue[i++]);
  120. // }
  121. // else
  122. // {
  123. // placeHolder++;
  124. // }
  125. //
  126. // }
  127. // for (int i = 0; i < LinkedArrays.length; i++) {
  128. // System.out.println(AgentID[i] +" "+ tc[i]);
  129. //
  130. // }
  131. File file = new File("D:\\AgentReport.txt");
  132. file.createNewFile();
  133. FileWriter rty=new FileWriter(file);
  134. BufferedWriter bw = new BufferedWriter(rty);
  135. for (int i = 0; i < PropertyType.length; i++) {
  136. bw.append(PropertyType[i]);
  137. bw.newLine();
  138. }
  139.  
  140. for (int i = 0; i < AgentID.length; i++) {
  141. bw.append(AgentID[i] + " "+ PropertyValue[i]+"\n");
  142. bw.newLine();
  143. }
  144. bw.close();
  145.  
  146.  
  147.  
  148. }
  149. catch(IOException e)
  150. {
  151. }
  152.  
  153. }
  154. }
Add Comment
Please, Sign In to add comment