Is there anyone who could guide me in the right direction on how to create an array of these employees? The array is set to a constant SIZE=10; Here is the my employee class and the driver with the array I tried. Also, I am aware that most of the output will be blank (employee name, id, etc) As I already know how to write it but so far have not. Also the "1" in class name "Employee 1" is only there because I already had another file saved under employee. Very new to java as you can most likely tell. Thank you
class Employee1{
//variables
private String name;
private double grossPay;
// This is the constructor of the class Employee
public Employee1(String EmpName)
{
name = EmpName;
}
//calculates gross pay and returns
public double weeklyPay(double hoursWorked, double hourlyRate)
{
double timeAndHalf = (hourlyRate/2.0)+hourlyRate;
double dblOvtHours;
double dblOvtPay;
double regHours;
double ovtHours;
if (hoursWorked <= 40)
{
grossPay = hoursWorked*hourlyRate;
}
else if (hoursWorked > 40 && hoursWorked <= 60)
{
ovtHours = hoursWorked-40;
regHours = 40;
grossPay = (ovtHours*timeAndHalf) + (regHours*hourlyRate);
}
else if (hoursWorked > 60)
{
ovtHours = 20;
regHours = 40;
dblOvtHours = hoursWorked - 60;
dblOvtPay = hourlyRate * 2;
grossPay = (dblOvtPay*dblOvtHours) + (timeAndHalf * ovtHours)
+(regHours * hourlyRate);
}
return grossPay;
}/////////////////////////////////////////////////
/* Print the Employee details */
public String toString()
{
return "Employee Report\n" + "Name :" + "\nID number :"
+ "\nHours Worked" + "\nHourly Rate : " +"\nGross pay: " + grossPay ;
}
}
my driver class:
import java.util.Scanner;
public class EmployeeDriver{
public static void main(String args[]){
// Invoking methods for each object created
final double hourlyRatef = 10.25;
double hoursWorkedf, wPay;
double grossPayf = 0.0;
Scanner input = new Scanner(System.in);
System.out.print("Please enter the number of hours work: ");
hoursWorkedf = input.nextDouble();
//array that does not work //
Employee1 emp = new Employee1();
emp[0] = new Employee ();
/* invoke weeklyPay() method */
grossPayf= emp.weeklyPay(hoursWorkedf,hourlyRatef);
// invoke printEmployee() method
System.out.println (emp.toString());
}
}