Could someone try to run this program and help me figure out why it seems really screwed up because not only is there a runtime error but it also is having trouble letting you type in your answer to the prompt. I have no idea what to do or what I've done wrong. I have no compile errors, only issues when I run the program. Specifically a runtime error.Any help would really be appreciated. Thank you!
The program itself is supposed to prompt 10 employees for their
last name
what time they started their work
(The time must entered by hour, then minute in military time. For ex., if they start work at 2:20 the user should enter 14 for the hour and 20 for the minute) `
what time they finished work
(also formatted like start time).
I'm assuming all data is entered correctly, that the employee finished work after they started, and that both times are for the same day.
The program will determine how many hours each employee worked that day.
It will output a well formatted report listing `
all of the employees
along with the amount of time they worked
(listed as hours and minutes),
also it should output
the average amount of time worked
their last name
This is what I've written-
import java.util.Scanner;
public class EmployeeTime
{
public static void main(String[] args)
{
String[] empLastName={""};
int[] workStartTime={0}, workEndTime={0}, totalTimeWorked={0}, hoursWorked={0};
double[] avgHoursWorked={0};
String[] empLastNameArray= new String[10];
int[] workStartTimeArray= new int[10];
int[] workEndTimeArray= new int[10];
double[] avgHoursWorkedArray= new double[0];
readEmployeeData(empLastName, workStartTime, workEndTime);
determineHoursWorked(workStartTime, workEndTime, totalTimeWorked);
determineAverageHoursWorked(workStartTime, workEndTime, totalTimeWorked);
writeHeadings();
printEmployeeInformation(empLastName, workStartTime, workEndTime);
}
public static void readEmployeeData(String[] empLastName, int[] workStartTime, int[] workEndTime)
{
System.out.println("enter how many students you would like to get the information");
Scanner input = new Scanner(System.in);
for(int i=0; i<10; i++)
{
System.out.println("Please enter your last name.");
empLastName[i]=input.next();
System.out.println("Please enter your work start time.");
workStartTime[i]=input.nextInt();
System.out.println("Please enter your work end time.");
workEndTime[i]=input.nextInt();
}
}
public static int[] determineHoursWorked(int[] workStartTime, int[] workEndTime, int[] totalTimeWorked)
{
int[] hoursWorked= new int[10];
for(int i=0; i<hoursWorked.length; i++)
hoursWorked[i]= workEndTime[i]-workStartTime[i];
for(int i=0; i<hoursWorked.length; i++)
{
totalTimeWorked[0]=totalTimeWorked[0]+hoursWorked[i];
}
return hoursWorked;
}
public static double[] determineAverageHoursWorked(int[] workStartTime, int[] workEndTime, int[] totalTimeWorked)
{
double[] avgHoursWorked= new double[10];
for(int i=0; i<avgHoursWorked.length; i++)
avgHoursWorked[0]= ((totalTimeWorked[0])/10);
return avgHoursWorked;
}
public static void writeHeadings()
{
System.out.printf("%s%25s%13s%16s\n\n", "Employees", "Amount of time worked", "Average amount of time worked");
}
public static void printEmployeeInformation(String[] empLastName, int[] hoursWorked, int[] avgHoursWorked)
{
for(int i=0; i<empLastName.length; i++)
System.out.printf("%-20s%9d%13.2f%16.2f\n", empLastName[i], hoursWorked[i], avgHoursWorked[i]);
}
}