Question: Write a public method for the Payroll class called showPayroll() that takes no arguments and returns no value. The method should iterate over programmers, and

Write a public method for the Payroll class called showPayroll() that takes no arguments and returns no value. The method should iterate over programmers, and print out the string representation of each programmer.

Programmer class

public class Programmer { /* static variables */ private static int nextId = 1; /* instance variables */ private int id; // programmer's id private String name; // programmer's name private int grade; // Determines pay; 1, 2 or 3 private int pay; // total pay in gold coins private int hours; // total hours worked

/** * Constructor for objects of class programmer */ public Programmer(String aName) { super(); this.name = aName; this.id = nextId ++; }

public int getId() { return this.id; }

public String getName() { return name; }

public int getGrade() { return grade; }

public void setGrade(int aGrade) { if (aGrade >= 1 && aGrade <= 3) { this.grade = aGrade; } else { throw new IllegalArgumentException("The grade " + aGrade + " does not exist"); } }

public int getPay() { return pay; }

public void setPay(int pay) { this.pay = pay; }

public int getHours() { return hours; }

public void setHours(int hours) { this.hours = hours; } }

Payroll class

public class Payroll { // instance variables private List programmers;

/** * Constructor for objects of class Payroll */ public Payroll() { // initialise instance variables programmers = new ArrayList<>(); }

/** * 4bii */ private int computePay(Programmer p) { return p.getGrade() * p.getHours(); } /** * 4biii */ public void readEmployeeData() { String pathname = OUFileChooser.getFilename(); File aFile = new File(pathname); BufferedReader bufferedFileReader = null; try { String programmerName; int programmerGrade; int programmerPay; int programmerHour; Scanner lineScanner; bufferedFileReader = new BufferedReader(new FileReader(aFile));

String currentLine = bufferedFileReader.readLine(); while (currentLine != null) { lineScanner = new Scanner(currentLine); lineScanner.useDelimiter(","); programmerName = lineScanner.next(); programmerGrade = lineScanner.nextInt(); programmerPay = lineScanner.nextInt(); programmerHour = lineScanner.nextInt(); Programmer programmerObject = new Programmer(programmerName); programmerObject.setGrade(programmerGrade); programmerObject.setPay(programmerPay); programmerObject.setHours(programmerHour); programmers.add(programmerObject); currentLine = bufferedFileReader.readLine(); //get the next line } } catch (Exception anException) { System.out.println("Error: " + anException); }

finally { try { bufferedFileReader.close(); } catch (Exception anException) { System.out.println("Error: " + anException); } } } /** * 4iv */ @Override public String toString()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!