Answer to Question #255183 in Java | JSP | JSF for Mike

Question #255183

Using a whole loop create a that calculates the monthly salaryof N [ where N is the number if employees that's entered by the user.] If the employee worked less or equal to 160 hours, the employee wilk be paid N$240.00 per hour. For any hour greater than 160, the employee is paid N$320.00 per hour.


1
Expert's answer
2021-10-22T16:47:29-0400


SOLUTION CODE FOR THE ABOVE QUESTION


package com.company;

import java.util.*;

public class Salary_calculator
{
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the number of Employees(N): ");
        int N = input.nextInt();
        if(N > 0)
        {
            //An array to store hours worked
            int [] array_for_hours_worked_by_employee = new int[N];
            int count_for_number_of_employees = 0;
            while(count_for_number_of_employees < N)
            {
                System.out.print("Enter hours worked by Employee "+(count_for_number_of_employees+1)+": ");
                int hours = input.nextInt();
                array_for_hours_worked_by_employee[count_for_number_of_employees] = hours;
                count_for_number_of_employees = count_for_number_of_employees+1;
            }
            //Calculate salary for each employee
            System.out.println("");
            int condition_count = 0;
            while(condition_count < N)
            {
                //check if the number of hours are more than 160
                if(array_for_hours_worked_by_employee[condition_count]>160)
                {
                    int salary = array_for_hours_worked_by_employee[condition_count]*320;
                    System.out.println("Monthly salary for Employee "+(condition_count+1)+" = N$"+salary);
                }
                else
                {
                    int salary = array_for_hours_worked_by_employee[condition_count]*240;
                    System.out.println("Monthly salary for Employee "+(condition_count+1)+" = N$"+salary);
                }
                condition_count = condition_count + 1;
            }

        }
        else if(N < 0)
        {
            System.out.println("Number of Employees cannot be negative");
        }
        else
        {
            System.out.println("No employees given to our program");
        }

    }
}



SAMPLE PROGRAM CODES FOR THE ABOVE PROGRAM



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