Hi all,
i seem to have gotten stuck on this coursework, i am unsure as to how to implement a method in the main class to calculate the sum of all employees monthly salaries.
Everything else works on the program it does output the employees details and their monthly salaries. I just need to add them up and output a "Total Payroll: xxxxxx.x " in this format. It sounds simple and it probably is simple, i think i can't see the woods for trees on this at the moment and just get confused, any help will be greatly appreciated.
i seem to have gotten stuck on this coursework, i am unsure as to how to implement a method in the main class to calculate the sum of all employees monthly salaries.
Everything else works on the program it does output the employees details and their monthly salaries. I just need to add them up and output a "Total Payroll: xxxxxx.x " in this format. It sounds simple and it probably is simple, i think i can't see the woods for trees on this at the moment and just get confused, any help will be greatly appreciated.
Code:
/*Class Main.java
*
*/
import Employees.Employee;
import Employees.StaffList;
import Employees.FullTimeEmployees;
import Employees.PartTimeEmployees;
import Employees.CommisionedEmployees;
/**
*
* @author
*/
public class Main
{
/**
*
* @param args
*/
public static void main(String[] args)
{
Employee[] staff = new Employee[9];
staff[0] = new FullTimeEmployees("STUART Charles",1002);
staff[1] = new PartTimeEmployees("MARPLE Jane",1005,10.5);
staff[2] = new CommisionedEmployees("SEYMOUR Thomas",1006,6500.0);
staff[3] = new FullTimeEmployees("AYDELJI Paul",1012);
staff[4] = new PartTimeEmployees("BROCK Sarah",1001,30.0);
staff[5] = new CommisionedEmployees("ALHAMBRA Alia",1003,3450.0);
staff[6] = new PartTimeEmployees("WHARTON Edith",1104,20.0);
staff[7] = new FullTimeEmployees("TURNER George",1111);
staff[8] = new CommisionedEmployees("BERNERS-LEE Tim",1014,7800.0);
printStaffList( staff);
}
static void printStaffList(Employee [] s)
{
for ( int i =0; i < 9; i++)
{
s[i].calculatePay() ; // THIS LINES COMPUTES PAY
System.out.println( s[i].toString());
}
}
private Main()
{
}
}
Code:
/*class Employee
*/
package Employees;
/**
* @author
*/
public abstract class Employee
{
protected String name; //Fields-containers that hold a value
protected double hrsWorked;
protected int empID;
protected static int lastEmpID = 1000;
protected double sales;
protected double hours;
protected double pay;
private double TotalPayD;
/**
*
*/
public Employee()
{
name = "";
hrsWorked = 0.0;
empID = ++lastEmpID ;
sales = 0.0;
hours = 40.00;
pay = 0.0;
TotalPayD = 0.0;
}
public Employee(String nm, double hrs, double p)
{
name =nm;
hours=hrs;
pay= p;
empID = ++lastEmpID ;
}
public abstract void calculatePay();
public double setHoursWorked( double hoursWorked)
{
return hoursWorked;
}
public double getHoursWorked( double hoursWorked)
{
return hoursWorked;
}
@Override
public String toString ()
{
return (" \n Name: " + name +
" \n WorksID: " + empID +
" \n Sales: " + sales +
" \n Hours: " + hours +
" \n Pay: " + pay +"");
}
}
Code:
/*class Employee
*/
package Employees;
/**
* @author
*/
*class FullTimeEmployees
*
*/
package Employees;
/**
* @author
*/
public class FullTimeEmployees extends Employee
{
double hrsWorked = 40.0; // ALL Full-Time staff work for 40 hours
/**
*
* @param nm
* @param id
*/
public FullTimeEmployees(String nm, int id)
{
name = nm ;
hours = hrsWorked ; // i.e. hours = 40.0
empID = id ;
}
@Override
public void calculatePay()
{
pay = hrsWorked * 2000.0 / 40.0 ;
}
}
Code:
/*class PartTimeEmployees
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Employees;
/**
*
* @author
*/
public class PartTimeEmployees extends Employee
{
/**
*
* @param nm
* @param id
* @param hr
*/
public PartTimeEmployees(String nm, int id, double hr)
{
name = nm ;
empID = id ;
hours = hr ;
}
@Override
public void calculatePay()
{
pay = hours * 2000.0 / 40.0 ;
}
}
Code:
/*class CommisionedEmployees
*/
package Employees;
/**
*
* @author
*/
public class CommisionedEmployees extends Employee
{
private static double commRate = 10.0 ;
private static double flatAmount = 1200.0 ;
public CommisionedEmployees(String nm, int id, double s)
{
name = nm ;
empID = id ;
sales = s ;
}
@Override
public void calculatePay()
{
pay = flatAmount + sales * (commRate / 100.0) ;
}
}
Code:
/*class StaffList
*
*/
package Employees;
import java.util.Collections;
public class StaffList
{
public StaffList(String string)
{
}
public void setStaffList()
{
}
public void getStaffList()
{
}
public void calculatePay()
{
}
public void printStaffList()
{
collections.sort();
}
//Collections.sort();
}
Comment