Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. /**
  4. * Created by maxim on 2017-04-27.
  5. */
  6. public class Blondes {
  7.  
  8. private String lastSchool;
  9. private String lastState;
  10. private String lastCity;
  11.  
  12. int blondeCount = 0;
  13.  
  14. public Blondes(String datarow) {
  15. String[] row = datarow.split("\t");
  16. lastCity = row[0];
  17. lastState = row[1];
  18. lastSchool = row[2];
  19. blondeCount = countBlonde(row[3]);
  20. }
  21.  
  22.  
  23. public int countBlonde(String gradeCount) {
  24. return Integer.parseInt(gradeCount.substring(1));
  25. }
  26.  
  27.  
  28.  
  29. public void processRow(String datarow) {
  30. String[] row = datarow.split("\t");
  31. if (!lastSchool.equals(row[2])) {
  32. System.out.println("BLONDE AT SCHOOL " + lastSchool + " " + blondeCount);
  33. blondeCount =+ countBlonde(row[3]);
  34. lastSchool = row[2];
  35. } else if (!lastState.equals(row[1])) {
  36. System.out.println("Blondes at state " + lastState + " " + blondeCount);
  37. blondeCount += countBlonde(row[3]);
  38. lastState = row[1];
  39. } else if (!lastCity.equals(row[0])) {
  40. System.out.println("Blondes in city " + lastCity + " " + blondeCount);
  41. blondeCount = countBlonde(row[3]);
  42. lastCity = row[0];
  43. }
  44. }
  45.  
  46.  
  47. public static void main(String[] args) throws IOException {
  48. try{
  49. InputStream fis = new FileInputStream("copyfile.txt");
  50. BufferedReader br = new BufferedReader(new InputStreamReader(fis));
  51.  
  52. String line;
  53. line = br.readLine();
  54. String[] test = line.split("\t");
  55. for (int i =0; i<test.length; i++) {
  56. System.out.println(test[i] + " lalal " + i);
  57. }
  58. Blondes derp = new Blondes(line);
  59.  
  60. while ((line = br.readLine()) != null) {
  61. derp.processRow(line);
  62. // System.out.println(line);
  63. }
  64. br.close();
  65. }
  66. catch(Exception e){
  67. System.out.println(e);
  68. System.err.println("Error: Target File Cannot Be Read");
  69. }
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement