Question
I am attempting to create a java program that reads employee data froma text file and produce a report. I get the following error when
I am attempting to create a java program that reads employee data froma text file and produce a report. I get the following error when running this code:
Java EmployeeSalary Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 at EmployeeSalary.main(EmployeeSalary.java:94)
The text file is:
2014 Employee Smith,John 2000 2014 Employee Carrol,Paul 1500 2015 Employee Gorley,Erica 3200 2014 Salesman Greeley,Susan 4500 40000 2015 Salesman Jones,Bill 3000 70000 2014 Executive Bush,George 5000 55 2014 Executive Smith,Frederick 7500 55
The code is below:
import java.lang.*; import java.io.*; import java.util.*;
class Employee{ public String employeeName; public int enteredYear, employeeMonthlySalary; public Employee(int year, String name, int monthlySalary){ enteredYear = year; employeeName = name; employeeMonthlySalary = monthlySalary; } public int annualSalary(){ return employeeMonthlySalary *12; } public String toString(){ return "Employee Name: "+employeeName+", Monthly Salary: $"+employeeMonthlySalary; } }
class Salesman extends Employee{ public int employeeAnnualSales; public Salesman(int year, String name, int monthlySalary, int annualSales){ super(year, name, monthlySalary); enteredYear = year; employeeName = name; employeeMonthlySalary = monthlySalary; employeeAnnualSales = annualSales; } public int annualSalary(){ return super.annualSalary()+ (int)Math.min(20000,employeeAnnualSales*.2); } public String toString(){ return super.toString()+", Annual Sales: "+employeeAnnualSales; } }
class Executive extends Employee{ public int currentStockPrice; public Executive(int year, String name, int monthlySalary, int stockPrice){ super(year, name, monthlySalary); enteredYear = year; employeeName = name; employeeMonthlySalary = monthlySalary; currentStockPrice = stockPrice; } public int annualSalary(){ int bonus = 30000; return (currentStockPrice > 50)? super.annualSalary() + bonus : super.annualSalary(); } public String toString(){ return super.toString()+", Stock Price: "+currentStockPrice; } }
class Name{ public String firstName, lastName; public Name(String nameString){ firstName = nameString.split(",")[1]; lastName = nameString.split(",")[0]; } public String getName(){ return firstName+" "+lastName; } }
public class EmployeeSalary{ private static ArrayList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started