Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- /**
- * Created by maxim on 2017-04-27.
- */
- public class Blondes {
- private String lastSchool;
- private String lastState;
- private String lastCity;
- int blondeCount = 0;
- public Blondes(String datarow) {
- String[] row = datarow.split("\t");
- lastCity = row[0];
- lastState = row[1];
- lastSchool = row[2];
- blondeCount = countBlonde(row[3]);
- }
- public int countBlonde(String gradeCount) {
- return Integer.parseInt(gradeCount.substring(1));
- }
- public void processRow(String datarow) {
- String[] row = datarow.split("\t");
- if (!lastSchool.equals(row[2])) {
- System.out.println("BLONDE AT SCHOOL " + lastSchool + " " + blondeCount);
- blondeCount =+ countBlonde(row[3]);
- lastSchool = row[2];
- } else if (!lastState.equals(row[1])) {
- System.out.println("Blondes at state " + lastState + " " + blondeCount);
- blondeCount += countBlonde(row[3]);
- lastState = row[1];
- } else if (!lastCity.equals(row[0])) {
- System.out.println("Blondes in city " + lastCity + " " + blondeCount);
- blondeCount = countBlonde(row[3]);
- lastCity = row[0];
- }
- }
- public static void main(String[] args) throws IOException {
- try{
- InputStream fis = new FileInputStream("copyfile.txt");
- BufferedReader br = new BufferedReader(new InputStreamReader(fis));
- String line;
- line = br.readLine();
- String[] test = line.split("\t");
- for (int i =0; i<test.length; i++) {
- System.out.println(test[i] + " lalal " + i);
- }
- Blondes derp = new Blondes(line);
- while ((line = br.readLine()) != null) {
- derp.processRow(line);
- // System.out.println(line);
- }
- br.close();
- }
- catch(Exception e){
- System.out.println(e);
- System.err.println("Error: Target File Cannot Be Read");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement