Answered You can hire a professional tutor to get the answer.

QUESTION

/** * Created by home1 on 9/6/2016. */ import java.*; import java.Scanner; import java.*; import java.Scanner; public class ComputeSalary { // Main...

I try to get the data in the employees.txt into the array of class. These are my code.

  • Attachment 1
  • Attachment 2
  • Attachment 3
  • Attachment 4
/*** Created by home1 on 9/6/2016.*/import java.io.*;import java.util.Scanner;import java.text.*;import java.util.Scanner;public class ComputeSalary {// Main methodpublic static void main(String args) throws FileNotFoundException// Import text file and compute salary increaseString fileName = "employees.txt";Scanner scanner=null;try {// Create a File instancescanner = new Scanner (new BufferedReader(newFileReader("employees.txt")));scanner.useDelimiter(","); { // Create arrays for 2014 and 2015Employee year_2014 = new Employee[20];Employee year_2015 = new Employee[20];// Create indexes for 2014 and 2015 arraysint indexYear2014 = 0, indexYear2015 = 0;// Read data from a filewhile (scanner.hasNextLine()) {String year = scanner.next();String employee_Title = scanner.next();String employee_Name = scanner.next();int monthly_Salary = scanner.nextInt();// Action if employee is a regular employee.if (employee_Title.equalsIgnoreCase("Employee")) {Employee regular_Employee = new Employee(employee_Name,monthly_Salary);if (year == "2014") {year_2014[indexYear2014++] = regular_Employee;} // end 2014 ifif (year == "2015") {year_2015[indexYear2015++] = regular_Employee;} // end 2015 if} // end Employee if// Action if employee is a salesman.if (employee_Title.equalsIgnoreCase("Salesman")){int annual_Sales = scanner.nextInt();Salesman sales_Employee = new Salesman(employee_Name,monthly_Salary, annual_Sales);if (year == "2014") {year_2014[indexYear2014++] = sales_Employee;} // end 2014 ifif (year == "2015") {year_2015[indexYear2015++] = sales_Employee;} // end 2015 if} // end Salesman if // Action if employee is an executive.if (employee_Title.equalsIgnoreCase("Executive")) {int currentStockPrice = scanner.nextInt();Executive executiveEmployee = new Executive(employee_Name,monthly_Salary, currentStockPrice);if (year == "2014") {year_2014[indexYear2014++] = executiveEmployee;} // end 2014 ifif (year == "2015") {year_2015[indexYear2015++] = executiveEmployee;} // end 2015 if} // end Executive if} // end While // Generate Report for 2014int totalSalary = 0;System.out.println("===== Salary Report for 2014 =====");for (int i = 0; i < indexYear2014; i++) {System.out.print(year_2014[i]);System.out.println(" Annual Salary: " +year_2014[i].Annual_Sal());} // end annualSalary 2014 forfor (int i = 0; i < indexYear2014; i++) {totalSalary+= year_2014[i].Annual_Sal();} // end totalSalary 2014 forSystem.out.println("\nAverage Salary for 2014: " +(totalSalary / indexYear2014));// Generate Report for 2015System.out.println("\n===== Salary Report for 2015 =====");for (int i = 0; i < indexYear2015; i++) {System.out.print(year_2015[i]);System.out.println(" Annual Salary: " +year_2015[i].Annual_Sal());} // end annualSalary 2015 forfor (int i = 0; i < indexYear2015; i++) {totalSalary+= year_2015[i].Annual_Sal();} // end totalSalary 2015 forSystem.out.println("\nAverage Salary for 2015: " +(totalSalary / indexYear2015));// Close input filescanner.close();} // end trycatch (IOException e) {System.out.println("Error: File Not Found");} // end catch} // end main method} // end ComputeEmployeeSalary class
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question