Limited access

Upgrade to access all content for this subject

A company has employees and each employee has a job title and a salary. Every month, the company’s human resource department analyzes the average salary for all employees as well as the average salary for each job title.

Which of the following would be the BEST way to represent the employee information in an object-oriented program?

A

Create a Company class that defines an ArrayList of job titles and another ArrayList of salaries. The elements in each ArrayList are aligned by index.

public class Company
{
    private ArrayList<String> jobTitles;
    private ArrayList<Double> salaries;

    // other instance variables and methods not shown
}
B

Create a Company class that defines two arrays, one that contains the job titles of each employee and another that contains their corresponding salaries. The elements in each array are aligned by index.

public class Company
{
    private String[] jobTitles;
    private double[] salaries;

    // other instance variables and methods not shown
}
C

Create a Company class and create instance variables for employee’s name, job title, salary, and other important information.

public class Company
{
    private String employeeName;
    private String jobTitle;
    private double salary;

    // other instance variables and methods not shown
}
D

Create a Company class that defines an instance variable representing an ArrayList that contains both the job title and the salary for every employee. Since this information would be stored in pairs, every other element is a job title (String), and every other element is the salary (double).

public class Company
{
    private ArrayList jobsAndSalaries;

    // other instance variables and methods not shown
}
E

Create an Employee class and create instance variables for job title, salary, and other important information. Then create a Company class that defines an instance variable that is an ArrayList containing the Employee objects.

public class Employee
{
    private String jobTitle;
    private double salary;

    // other instance variables and methods not shown
}

public class Company
{
    private ArrayList<Employee> employees;

    // other instance variables and methods not shown
}
Select an assignment template