Is it possible to calculate data member different constructors?

115 Views Asked by At

I'm doing an assignment on creating an STP - A Payroll Management System for a company. I was given 11 classes (Employee, Employees, Employer, Employers, STP, STPLog, Report, In, Session, Utils) I just finished initializing data members in Employee and Employers but in STP, there are members which require calculation from the members in Employee. For example: totalWages = sum of 'income' in Employee. Im just wondering if it's possible to do that calculation in STP constructor? And the way to do so? Because I can do that in Employee with its data members. Here's my code:

//STP.java//
import java.util.ArrayList;
import java.util.Date;

public class STP {
    private double totalWages;
        
public STP (double totalWages){
   this.totalWages = totalWages; 
>                    ---------^ part need to calculate 
  }


}
//Employee.java//
public class Employee {
    
    private int hours;
    private double payPerHour;
    private double income;
    

    public Employee (int hours, double payPerHour) {
        
        this.hours = hours;
        this.payPerHour = payPerHour;
        this.income = hours*payPerHour*52;
        
    }
    
    
}

0

There are 0 best solutions below