Write a Java Program to find the average salary of employees excluding the minimum and maximum salary. Assume an array of unique integers salary where salary[i] is the salary of the ith employee.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
**Task: Calculate Average Salary Excluding Extremes with Java**

**Objective:**

Write a Java program to calculate the average salary of employees, excluding the minimum and maximum salaries.

**Instructions:**

1. You have an array of unique integers called `salary`.
2. Each element `salary[i]` represents the salary of the `i`th employee.
3. Your task is to compute the average salary excluding the lowest and highest salaries from this array.

Use these instructions to implement a method that processes the `salary` array and accurately computes the required average.
Transcribed Image Text:**Task: Calculate Average Salary Excluding Extremes with Java** **Objective:** Write a Java program to calculate the average salary of employees, excluding the minimum and maximum salaries. **Instructions:** 1. You have an array of unique integers called `salary`. 2. Each element `salary[i]` represents the salary of the `i`th employee. 3. Your task is to compute the average salary excluding the lowest and highest salaries from this array. Use these instructions to implement a method that processes the `salary` array and accurately computes the required average.
Expert Solution
Average salary of employees excluding the minimum and maximum salary

In the problem ”Average Salary Excluding the Minimum and Maximum Salary” we are given a salary array. where each element in the array represents the salary of different employees. Each value in the array is unique.

Our task is to calculate the average salary of the employee excluding the minimum and the maximum salary.

Explanation:

 

In the let the salary array 9000 is the maximum salary and 1000 is the minimum salary. As we need to find the average salary excluding the minimum and maximum salary so we will not add these values to the total sum. The total sum is 19000 so the average is 19000/4 that is 4750.

Approach

This is a basic math problem. Our task is to find the minimum and the maximum salary then find the average of the remaining salary. We will follow these steps:

  1. Initialize minimum salary with INT_MAX, the maximum salary with INT_MIN. We will use a variable to store the salary sum so initialize it with 0.
  2. Traverse the array and add each salary to the sum. Meanwhile, also update the value of the minimum salary and maximum salary.
  3. If the value of n is smaller than three then the average salary will be zero else average salary will be (total salary-the minimum salary-the maximum salary)/(n-2).
  4. We will multiply (n-2) with 1.0 because the average salary can be a double value.
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY