Question

In: Computer Science

Your company has asked you to develop a report detailing payroll information with the following format:...

Your company has asked you to develop a report detailing payroll information with the following format:

Acme Corporation

Number of Employees: 3
Average Salary: 70,530.70
Annual Total: 211,592.09

Name Rank Salary
Gator, Allie A2 48,000.00
Mander, Sally A1 61,123.89
Zah, Pete A1 102,468.20

Develop an Employee class that contains first name, last name, rank, and salary. The class should have the following methods:

parameterized constructor
getters necessary for printing the report
formatName() method that returns a String with the name in the format last, first

Employee information is stored in a sequential text file named employees.txt. The file has the format:

employees.txt file: text file with the following fields separated by spaces:
Fields Description
First Name string
Last Name string
Rank string
Salary double
Note: Names will not contain spaces.

Write a program named Prog5 that reads employee information from the file and places a corresponding Employee object into an array. After the file has been read, print the report shown above using proper formatting.

Challenge

For those who would like a challenge to increase the difficulty of the assignment, implement the following static methods to be used to print the average salary and annual total, both of which receive an array of doubles and the number of elements in the array:

averageSalary( Employee arr[], int numreturns the average salary of employees in the array
totalSalary( Employee arr[], int num ) returns the sum of all salaries of employees in the array

Note: This is not required and should not be attempted until you have the basic assignment completed.


Requirements

• Your source code should follow the Java programming standards for the course.
• Your source code should be documented using Javadoc style according to the course standards.
• Use the default package in your project; do not specify a package in your code.
• Use any file and class names specified in the assignment.

Solutions

Expert Solution

Program :

see the program screenshots for the indentation reference!

Employee.java

/*
*The employees class 
*/
public class Employee
{
    /*
    *private data members
    */
    private String firstName;
    private String lastName;
    private String rank;
    private double salary;
    
    /*
    *parameteraized constructor
    */
    public Employee(String fname,String lname,String rank,double salary)
    {
        this.firstName = fname;
        this.lastName = lname;
        this.rank = rank;
        this.salary = salary;
    }
    
    /*
    *Getter methods
    */
    public  String getFirstName()
    {
        return firstName;
    }
    public String getLastName()
    {
        return lastName;
    }
    public String getRank()
    {
        return rank;
    }
    public double getSalary()
    {
        return salary;
    }
    
    /* 
    *format name method with lastName, firstName
    */
    public String formatName(){
        return lastName + ", "+firstName;
    }
    
    /* 
    *method to calculate Total salary of the all employees passed as array of employee 
    */
    public static double totalSalary(Employee arr[], int num)
    {
        double total=0;
        for(int i=0; i<num; i++)
        {
            total = total + arr[i].getSalary();
        }
        return total;
    }
    
    /* 
    *method to calculate average salary of the all employees passed as array of employee 
    */
    public static double averageSalary(Employee arr[], int num)
    {
        return totalSalary(arr,num)/num;
    }
}

Prog5.java

import java.io.File; 
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner; 
import java.util.ArrayList;
public class Prog5
{
    public static void main(String args[])
    {
        /*
        Reading all lines from the employees.txt file in the arraylist of Strings
        */
        ArrayList<String> lines = new ArrayList<String>();
        try {
            // pass the path to the file as a parameter 
            File file = new File("employees.txt"); 
            BufferedReader br = new BufferedReader(new FileReader(file));  
            String line; 
            while ((line = br.readLine()) != null) 
            {
                lines.add(line);
            } 
        } catch(Exception e) {
            System.out.println(e);
        } 
        
        /*
        *Number of lines present in the file
        */
        int num = lines.size();
        
        /*
        *Creating the array of employees
        */
        Employee employees[] =  new Employee[num];
        
        /*
        *for each of the line in the employees.txt
        *create the Employee object
        */
        int i=0;
        for(String line : lines)
        {
            String tokens[] = line.split(" ");
            employees[i] = new Employee(tokens[0], tokens[1], tokens[2], Double.parseDouble(tokens[3]));
            i++;
        }
        
        
        /*
        *Displaying the details of the employees 
        */
        System.out.println("Acme Corporation\n");
        System.out.println("Number of Employees: "+num);
        System.out.println("Average Salary: "+String.format("%,.2f",Employee.averageSalary(employees,num)));
        System.out.println("Annual Total: "+String.format("%,.2f",Employee.totalSalary(employees,num)));
        System.out.println();
        System.out.println("Name\t\tRank\tSalary");
        for(Employee e : employees)
        {
            System.out.println(e.formatName()+"\t"+e.getRank()+"\t"+String.format("%,.2f", e.getSalary()));
        }
    }
}

employees.txt

Allie Gator A2 48000.00
Sally Mander A1 61123.89
Pete Zah A1 102468.20

Output Screenshot :

Program screenshots for indentation reference :


Related Solutions

The board of directors has asked that you provide a 750-word report detailing your strategies and...
The board of directors has asked that you provide a 750-word report detailing your strategies and recommendations to contract with a disease management company in order to reduce utilization costs and to improve patient health outcomes. Your report should outline the specific interventions and model that will be used by Regional Hospital. Your presentation should also explain cost projections and savings over a 10-year period.
Project flow and Report Format The following information must be included in your report: Abstract Table...
Project flow and Report Format The following information must be included in your report: Abstract Table of Content List of Figures List of Tables LIST OF ABBREVIATIONS Part 1: Introduction Part 2: Literature Review Part 3: Methodology Part 4: Result and Discussion Part 5: Conclusions Part 6: References Appendix
Your company asked you to develop a new software. Explain the following : 1. What software...
Your company asked you to develop a new software. Explain the following : 1. What software development methodology you will use and why? 2. List two models, tools, and techniques you will use and explain why you used each one?
In your first assignment on the job, your supervisor has asked you to report on the...
In your first assignment on the job, your supervisor has asked you to report on the company’s competitors future products. You really want to succeed. What do you do? A. You could call the competitors pretending you are a college student working on project needing information B. You could ask a college friend to call the competitors and ask for the information C. You could call the competitors, but would not tell them who you really are unless if asked...
CC3D- If you were asked by your employer to develop a new Information Security Policy, where...
CC3D- If you were asked by your employer to develop a new Information Security Policy, where would you turn to find resources to build this policy? List the two most important items you would include in this new policy and explain why you felt these were most important.
You are asked to develop a database for your city. Which of the following statements are appropriate?
You are asked to develop a database for your city. Which of the following statements are appropriate?You look for a database that offers transaction processing for municipal dataYour application should most likely be based on a general purpose database management system, and the meta data specific to your application will be stored in much the same way as the dataIf you can find a vendor for an application that is specific to your needs, such an application will likely have...
You are the new controller for Banana, Inc.. The company CFO has asked you to develop...
You are the new controller for Banana, Inc.. The company CFO has asked you to develop the appropriate worksheets and then journal entries to support several lease contracts as applied based on the new lease regulations. Your accounting group provided you the following information regarding the lease: On January 2, 2019, another of Banana’s subsidiaries, Apple, entered into an operating lease for four years, with semi-annual lease payments as follows:  payments 1 and 2 = $22,500; payments 3 and 4 =...
You are the new controller for Banana, Inc..  The company CFO has asked you to develop the...
You are the new controller for Banana, Inc..  The company CFO has asked you to develop the appropriate worksheets and then journal entries to support several lease contracts as applied based on the new lease regulations.  Your accounting group provided you the following information regarding the lease: On January 2, 2019, Banana’s subsidiary, Cream, entered into an equipment lease for four years, with semi-annual payments, for a machine that had an eight (8) year life and a fair value of $420,000.  The payments...
You are the new controller for Banana, Inc.. The company CFO has asked you to develop...
You are the new controller for Banana, Inc.. The company CFO has asked you to develop the appropriate worksheets and then journal entries to support several lease contracts as applied based on the new lease regulations. Your accounting group provided you the following information regarding the lease: On January 2, 2018, Banana leased equipment, with a fair value of $675,000, under a capital lease calling for seven annual lease payments of $110,000 beginning January 2, 2018, and continuing each December...
One of the partners at your firm has asked you to develop an office training presentation...
One of the partners at your firm has asked you to develop an office training presentation to familiarize your audit team with sampling models that can be used for auditing monetary balances. The partner wants you to include the following information in your presentation: The relationship of sample sizes to population sizes. Estimated population exception rate. The acceptable guidelines for establishing tolerable misstatement.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT