Hi. I have a reader class (code below) that just reads over a text file and puts items into a comma-delimited array. Items in the text file are int positionCode and String positionTitle, in the form:
102,Manager
248,DeptHead
299,Assistant
etc...
My question is: Is there a way to put ONLY the position codes (int) into a separate array?
**I want to write a method in another class that finds the position code with the lowest value.**
Is putting them in a separate array the best way or should I do it another way and how?
Code:import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * reads in an employee's position in a department into memory */ public class PositionReader { private BufferedReader in; private Company Company; /** * constructor * @param fileName * @throws FileNotFoundException */ public PositionReader(String fileName, Company company) throws FileNotFoundException { in = new BufferedReader(new FileReader(fileName)); this.Company = company; } /** * reads a position from text file * @return position */ public Position readPosition() { String line; try { line = in.readLine(); if (line == null || line.trim().length() == 0) { return null; } String[] fields = line.split(","); int positionCode = Integer.parseInt(fields[0]); String positionTitle = fields[1]; Position position = new Position(positionCode, positionTitle); return position; } catch (IOException e) { return null; } } public void close() throws IOException { in.close(); } }


Reply With Quote

Bookmarks