Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use java to construct this program. Also provide in detail the descriptio

ID: 3682101 • Letter: P

Question

Please use java to construct this program. Also provide in detail the description so i can understand whats going on in the code.

The first programming project involves writing a program that computes the salaries for a collection of employees of different types. This program consists of four classes.

The first class is the Employee class, which contains the employee's name and monthly salary, which is specified in whole dollars. It should have three methods:A constructor that allows the name and monthly salary to be initialized.A method named annualSalary that returns the salary for a whole year. A toString method that returns a string containing the name and monthly salary, appropriately labeled.

The Employee class has two subclasses: Salesman and Executive.

The Salesman class has an additional instance variable that contains the annual sales in whole dollars for that salesman.

It should have the same three methods: A constructor that allows the name, monthly salary and annual sales to be initialized. An overridden method annualSalary that returns the salary for a whole year. The salary for a salesman consists of the base salary computed from the monthly salary plus a commission. The commission is computed as 3% of that salesman's annual sales. The maximum commission a salesman can earn is $25,000. An overridden toString method that returns a string containing the name, monthly salary and annual sales, appropriately labeled.

The Executive class has an additional instance variable that reflects the current stock price.

It should have the same three methods: A constructor that allows the name, monthly salary and stock price to be initialized. An overridden method annualSalary that returns the salary for a whole year. The salary for an executive consists of the base salary computed from the monthly salary plus a bonus. The bonus is $20,000 if the current stock price is greater than $100 and nothing otherwise. An overridden toString method that returns a string containing the name, monthly salary and stock price, appropriately labeled.

Finally there should be a fourth class that contains the main method. It should read in employee information from a text file input.txt. Each line of the text file will represent the information for one employee for one year. An example of how the text file will look is shown below:

2014 Employee Smithson,John

2000 2015 Salesman Jokey,Will 3000 100000

2014 Executive Bush,George 5000 150

The year is the first data element on the line. The file will contain employee information for only two years: 2014 and 2015. Next is the type of the employee followed by the employee name and the monthly salary. For salesmen, the final value is their annual sales and for executives the stock price. As the employees are read in, Employee objects of the appropriate type should be created and stored in an array depending upon the year (there should be two arrays, one corresponding to 2014 and one corresponding to year 2015). You may assume that the file will contain no more than 20 employee records for each year and that the data in the file will be formatted correctly.

Once all the employee data is read in, a report should be displayed on the console for each of the two years. Each line of the report should contain all original data supplied for each employee together with that employee's annual salary for the year. For each of the two years, an average of all salaries for all employees for that year should be computed and displayed.

Your program should compile without errors.

Be sure to follow good programming style, which means making all instance variables private, naming all constants, avoiding the duplication of code and using Java code conventions. Furthermore you must select enough different kinds of employees to completely test the program.

(again please provide lots of descriptions so i can lean how to construct a similar program)

Explanation / Answer

import java.io.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class MainApp {

    // Private ArrayLists for each year of employee data
    private ArrayList<Employee> employeeArrayList2014 = new ArrayList<>();
    private ArrayList<Employee> employeeArrayList2015 = new ArrayList<>();

    // Private DecimalFormat object to be used by functions in the MainApp class
    private static DecimalFormat df = new DecimalFormat("$0.00");


    public void builder() {

        try {

            Scanner input = new Scanner(new File("data.txt"));

            // Completes loop when "input.nextLine();" below detects no data
            while (input.hasNext()) {

                int year = input.nextInt();

                // Tests for 2014 in the first element
                if (year == 2014) {
                    String type = input.next();
                    String name = input.next();
                    double monthlySalary = input.nextDouble();

                    // Tests for Salesman in the second element
                    if (type.equals("Salesman")) {
                        double salesOrStock = input.nextDouble();
                        employeeArrayList2014.add(new Salesman(year, name, monthlySalary, salesOrStock));

                    // Tests for Executive in the second element
                    } else if (type.equals("Executive")) {
                        double salesOrStock = input.nextDouble();
                        employeeArrayList2014.add(new Executive(year, name, monthlySalary, salesOrStock));

                    // If neither Salesman or Executive test happened, it is an Employee
                    } else {
                        employeeArrayList2014.add(new Employee(year, name, monthlySalary));
                    }

                // Tests for 2015 employees
                } else if (year == 2015) {
                    String type = input.next();
                    String name = input.next();
                    double monthlySalary = input.nextDouble();

                    // Tests for Salesman in the second element
                    if (type.equals("Salesman")) {
                        double salesOrStock = input.nextDouble();
                        employeeArrayList2015.add(new Salesman(year, name, monthlySalary, salesOrStock));

                        // Tests for Executive in the second element
                    } else if (type.equals("Executive")) {
                        double salesOrStock = input.nextDouble();
                        employeeArrayList2015.add(new Executive(year, name, monthlySalary, salesOrStock));

                    // If neither Salesman or Executive test happened, it is an Employee
                    } else {
                        employeeArrayList2015.add(new Employee(year, name, monthlySalary));
                    }
                }

                // Completes when a blank line is detected
                input.nextLine();

            }

        } catch (IOException e) {
            System.out.println("File not found.");
            e.printStackTrace();
        } catch (NullPointerException e) {
            System.out.println("A null pointer was found, please check the input file.");
            e.printStackTrace();
        } catch (NoSuchElementException e) {
            System.out.println("The last line of the document is not blank.");
            e.printStackTrace();
        }
    }


    public void displayAllEmployees() {

        // Placeholder variables to sum and average the salary
        double averageSalary2014 = 0;
        double averageSalary2015 = 0;

        // Iterate through, and display 2014 data first
        System.out.println(" 2014 Data:");
        for (Employee em : employeeArrayList2014) {
            System.out.println(em.toString());
            averageSalary2014 += em.annualSalary();

        }

        // averageSalary2014's final value should be itself divided by the number of employees
        averageSalary2014 = averageSalary2014 / employeeArrayList2014.size();
        System.out.println("=========================================");
        System.out.println("The average salary for 2014 was: " + df.format(averageSalary2014));

        // Iterate through, and display 2015 data after 2014 has completed
        System.out.println(" 2015 Data:");
        for (Employee em : employeeArrayList2015) {
            System.out.println(em.toString());
            averageSalary2015 += em.annualSalary();
        }

        // averageSalary2015's final value should be itself divided by the number of employees
        averageSalary2015 = averageSalary2015 / employeeArrayList2015.size();
        System.out.println("=========================================");
        System.out.println("The average salary for 2015 was: " + df.format(averageSalary2015));
    }

    public static void main(String[] args) {
        MainApp list = new MainApp();
        list.builder();
        list.displayAllEmployees();
      
    }
}

Employee.java
import java.text.DecimalFormat;

public class Employee {

    private String name;
    private double monthlySalary;
    private int year;
    protected static DecimalFormat df = new DecimalFormat("$0.00");
    public Employee() {

    }

    public Employee(int year, String name, double monthlySalary) {
        this.year = year;
        this.name = name;
        this.monthlySalary = monthlySalary;
    }
    public double annualSalary() {
        return this.monthlySalary * 12;
    }

    public String toString() {
        return " Employee Name: " + this.name +
                " Annual Salary: " + df.format(this.annualSalary());
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMonthlySalary() {
        return monthlySalary;
    }

    public void setMonthlySalary(double monthlySalary) {
        this.monthlySalary = monthlySalary;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }
}


Salesman.java
public class Salesman extends Employee {

    private double annualSales;

    public Salesman() {

    }

    public Salesman(int year, String name, double monthlySalary, double annualSales) {
        super(year, name, monthlySalary);
        this.annualSales = annualSales;
    }

    public double annualSalary() {
        double commission = this.annualSales * .02;

        // The maximum commission a salesman can earn is $20,000.
        if (commission > 20000) {
            commission = 20000;
        }

        return super.annualSalary() + commission;
    }

    @Override
    public String toString() {
        return super.toString() + " Annual Sales: " +
                df.format(this.annualSales);
    }


    public double getAnnualSales() {
        return annualSales;
    }

    public void setAnnualSales(double annualSales) {
        this.annualSales = annualSales;
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void setName(String name) {
        super.setName(name);
    }

    @Override
    public double getMonthlySalary() {
        return super.getMonthlySalary();
    }

    @Override
    public void setMonthlySalary(double monthlySalary) {
        super.setMonthlySalary(monthlySalary);
    }

    @Override
    public int getYear() {
        return super.getYear();
    }

    @Override
    public void setYear(int year) {
        super.setYear(year);
    }
}


data.txt
2014 Employee Smith,John 2000
2015 Employee Smith,John 2300
2014 Salesman Jones,Bill 2800 88000
2015 Salesman Jones,Bill 3000 100000
2014 Executive Bush,George 5000 55
2015 Executive Bush,George 5600 48
2014 Employee Scott,Dawn 1800
2015 Employee Scott,Dawn 3400
2014 Salesman Regan,Karol 3100 940000
2015 Salesman Regan,Karol 3500 1040000
2014 Executive Lowman,Nora 4400 55
2015 Executive Lowman,Nora 4800 48
2014 Employee Hendrix,Elliot 2500
2015 Employee Hendrix,Elliot 2600
2014 Salesman Hennis,Tyler 2700 75000
2015 Salesman Hennis,Tyler 2700 73000
2014 Executive Bollig,Dee 4500 55
2015 Executive Bollig,Dee 4900 48
2014 Employee Hughes,Jacob 2800
2015 Employee Hughes,Jacob 3100

sample output

2014 Data:                                                                                                                                                  
                                                                                                                                                            
Employee Name:                  Smith,John                                                                                                                  
Annual Salary:                  $24000.00                                                                                                                   
                                                                                                                                                            
Employee Name:                  Jones,Bill                                                                                                                  
Annual Salary:                  $35360.00                                                                                                                   
Annual Sales:                   $88000.00                                                                                                                   
                                                                                                                                                            
Employee Name:                  Bush,George                                                                                                                 
Annual Salary:                  $90000.00                                                                                                                   
Current Stock Price:            $55.00                                                                                                                      
                                                                                                                                                            
Employee Name:                  Scott,Dawn                                                                                                                  

Annual Salary:                  $21600.00                                                                                                                   
                                                                                                                                                            
Employee Name:                  Regan,Karol                                                                                                                 
Annual Salary:                  $56000.00                                                                                                                   
Annual Sales:                   $940000.00                                                                                                                  
                                                                                                                                                            
=========================================                                                                                                                   
The average salary for 2014 was: $49126.00                                                                                                                  
                                                                                                                                                            
2015 Data:                                                                                                                                                  
                                                                                                                                                            
Employee Name:                  Smith,John                                                                                                                  
Annual Salary:                  $27600.00                                                                                                                   
                                                                                                                                                            
Employee Name:                  Jones,Bill                                                                                                                  
Annual Salary:                  $38000.00                                                                                                                   
Annual Sales:                   $100000.00                                                                                                                  
                                                                                                                                                            
Employee Name:                  Bush,George                                                                                                                 
Annual Salary:                  $67200.00                                                                                                                   
Current Stock Price:            $48.00                                                                                                                      
                                                                                                                                                            
Employee Name:                  Hughes,Jacob                                                                                                                
Annual Salary:                  $37200.00                                                                                                                   
=========================================

                                                                                                                 
The average salary for 2015 was: $45426.00