Answer to Question #273467 in Java | JSP | JSF for dhyfullah

Question #273467

A company dealing with marketing wants to manage the data of its employees. Each employee has a full name, unique employee number (2019000 to 2019999) and the number of hours he worked and her hourly wage (price).


Write a method “calculateSalary” that calculates the weekly salary of an employee

Write a method “calculateAverage” that calculates the average of weekly salaries

Write a method “calculateAmount” that calculates the total amount of salaries

Write a java program that uses the above method to meets the needs of this company. it performs the following tasks:

Read from the standard input the number n of employees

Read from the standard input the employee characteristics. Use arrays to store the full names, worked hours and hour prices of the n employees read from the console.

Uses the above methods to calculate salaries of employees, calculate the average and the sum of the salaries.

Print each employee with its salary on a separate line.

Print the average and the sum of salaries


1
Expert's answer
2021-11-30T18:19:16-0500
import java.util.Scanner;

public class Main {
    public static double calculateSalary(int hours, double hourlyWage) {
        return hourlyWage * hours;
    }

    public static double calculateAverage(double[] salaries) {
        return calculateAmount(salaries) / salaries.length;
    }

    public static double calculateAmount(double[] salaries) {
        double total = 0;
        for (double salary : salaries) {
            total += salary;
        }
        return total;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter the number of employees:");
        int n = Integer.parseInt(in.nextLine());
        String[] names = new String[n];
        int[] employeeNumbers = new int[n];
        int[] numberOfHours = new int[n];
        double[] hourlyWages = new double[n];
        double[] salaries = new double[n];
        for (int i = 0; i < n; i++) {
            System.out.println("Name:");
            names[i] = in.nextLine();
            System.out.println("Employee number:");
            employeeNumbers[i] = Integer.parseInt(in.nextLine());
            System.out.println("Number of hours:");
            numberOfHours[i] = Integer.parseInt(in.nextLine());
            System.out.println("Hourly wage:");
            hourlyWages[i] = Double.parseDouble(in.nextLine());
            salaries[i] = calculateSalary(numberOfHours[i], hourlyWages[i]);
        }
        for (int i = 0; i < n; i++) {
            System.out.println(names[i] + " " + employeeNumbers[i] + " " + numberOfHours[i] +
                    "h " + hourlyWages[i] + "$/h " + salaries[i] + "$");
        }

        System.out.println("Average: " + calculateAverage(salaries) + " Total: " + calculateAmount(salaries));
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS