Java – class, get new array of objects

You may need to review basic OOP, object-oriented programming. Variables defined in Worker and Department should be private, using methods such as getID() and setID(String ID). The workers should be stored in an ArrayList like this:

ArrayList<Worker> workers = new ArrayList<Worker>();
workers.add(new Worker(*input proper data*));

If you plan to sum the workers’ salaries, you may loop through workers by using a for-each loop:

int sum = 0;
for(Worker w : workers){
sum += w.calculateSalary(w.getH());//you may need to include an "h" variable in the worker class
}

Also, these calls:

work1.calculateSalery(55);
work2.calculateSalery(60);

Are absolutely pointless since you’re not storing these calculations anywhere. Since calculateSalery(); returns type int you may store these values in an int variable. However, you may want to use double variable types for things such as Hourly_Wage, Number_Of_Hours, and the method calculateSalery();

Leave a Comment