So I had to define all the method for class company and implement the main method as well. I'm reading a file from my C: drive, I am using filereader and bufferedreader to read the file and then read it line by line. I need to output what's on the file. I was also wondering if I could print out the info w/out the use of a toString().
(this is what's in the text file in my c drive)
123
45000.00
456
60000.00
321
55000.0
567
80000.0
111
37000.0
import java.io.*; class Test { public static void main (String[] args) { //Create comp company object Company comp = new Company(5); //Read the total payroll try { comp.readPayrollData(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //Compute the payroll data comp.computePayroll(); }//End main }//End class Test public class Employee { private String empID; private double pay; public Employee(){} public Employee(String id, double pa) { empID = id; pay = pa; }//End Employee double getPay() { return pay; }//end getpay }//End class Employee /*Author: JCont * Class company provides the following constructor methods * for processing the data stored in the array and for * computing the company payroll. */ import java.io.*; public class Company { //Declare data, array of employees and payroll for company. private Employee[] employees; private double payroll; public Company(int size) { employees = new Employee[size]; } // Method setPayRoll will store argument in variable payroll. public void setPayRoll(double p) { payroll = p; } //validate range of index #'s. private boolean Range(int i) { return i >= 0 && i < employees.length; } //If valid range then will store employees in a certain index. public void setemployees(Employee e, int i) { if (Range(i)) { employees[i] = e; } } //If there is a valid range if indices then will return that employees, otherwise null. public Employee getemployees(int i) { if(Range(i)) { return employees[i]; } else { return null; } }//End Employee getemployees //Read data from a file called employees.txt and store them in array "employees" public void readPayrollData() throws Exception { try{ FileReader fr = new FileReader("c:\\employees.txt"); BufferedReader br = new BufferedReader(fr); String id; //id = br.readLine(); //while((id != null)) for(int i = 0;(id = br.readLine()) != null;i++) { String tempsalary = br.readLine(); double salary = Double.parseDouble(tempsalary); Employee emp = new Employee(id, salary); employees[i] = emp; }//end for fr.close(); }//end try block catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }//end readPayrollData public void computePayroll() { for(int i = 0; i < employees.length;i ++) { payroll = (employees[i].getPay() ); } }//end Compute payroll }//End class