View Single Post
  #13 (permalink)  
Old 05-08-2008, 06:58 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
// change this public static void Main(String empName, double hoursWorked, double payRate, double total) // to this public static void main() ... // To get your class to work with these two statements Employee employee = new Employee(); Employee employee = new Employee(empName, hoursWorked, payRate, total); // you would have to add more constructors: class Employee { public String empName; double hoursWorked; double payRate; double total; public Employee() { this(null, 0.0, 0.0); } public Employee(String name, double hours, double rate) { this(name, hours, rate, 0.0); computeWeeklyPay(); } public Employee(String name, double hours, double rate, double total) { this.empName = name; this.hoursWorked = hours; this.payRate = rate; this.total = total; } ...
or you could change the constructor in the Main class to
Code:
Employee employee = new Employee(empName, hoursWorked, payRate);
and call computeWeeklyPay() in the Employee constructor to calculate total as you had it.

Last edited by hardwired : 05-08-2008 at 07:13 AM. Reason: more to say after a second look
Reply With Quote