Explore BrainMass

Create an Array with Elements Entered by a User Via a Prompt.

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Write a javascript to create an array with 5 elements. Then load the elements with first names read from the user via prompt.

© BrainMass Inc. brainmass.com October 25, 2018, 6:59 am ad1c9bdddf

Solution Summary

This solution contains an attached javascript code to create an array of 5 elements entered by the user via prompt and then they are printed.

See Also This Related BrainMass Solution

**Java** Calculating Payroll

Company weekly payroll. The input will be a list of hours worked by employees. The output will be the list of amounts owed to each employee plus a total sum of the amounts owed.

Use two methods that work with arrays that contain the payroll data. The first method, which will be called getPayrollData(), will be called from main() in order to get the payroll data from the user. It must do the following:

Prompt the user for the number of employees to be processed.
Create an array of the size needed to hold the hours worked for this many employees. This should be an array of int since the company requires that full hours be worked.

Input the hours worked into the array using a loop and identifying employees as described further down.

Pass the array back to main() as the return value of the method.
You will create a second method called processPayroll() that returns an array of doubles. It will take the hours worked array as a parameter and process it. This method must do the following:

Receive the array from main() as a parameter.

Create a new array of doubles to hold the wages information for each employee. This second wages array will have to be the same size as the hours worked array.

Process the data elements by calculating the wages owed to the employee for the number of hours worked and loading this data into the corresponding element of the wages array. The calculation of wages will be done at a fixed pay rate of $38.57/hour with time and a half for over time where over time is any number of hours worked in excess of 40 hours.
Return the wages array.

When processPayroll() returns to main() the code in main() will do two things:

Print out the list of employees identifying them by the array index as described below, how many hours were worked, and and how much is owed to each one.

Print out the sum total of money owed by the company for the payroll.
To make it simple to associate employees to array elements we will assume that the company identifies employees by a payroll number. This number conveniently begins with 100 for the first employee and counts up from there. So you can just add 100 to the array index for the particular employee to display the employee number. You must show the employee number during the input process by prompting for the hours worked by that employee number. You must also print the employee number when displaying the output list of amounts owed to each employee. This means that data for employee #100 is in array location 0, #101 in array location 1, etc.

The input/output format must duplicate the format shown in the sample run below. The user inputs are shown in blue text. You must use printf() to make the amounts in dollars print with two decimal places of accuracy.

Enter number of employees: 4
Enter below the hours worked for the employee number:
#100: 40
#101: 43
#102: 37
#103: 40

Payroll Report:

Emp Number Hours Wages($)
---------- ----- ---------

100 40 1542.80
101 43 1716.37
102 37 1427.09
103 40 1542.80

Total wages: $6229.06

A template program is attached to help you get started and to get things structured the way they need to be.

View Full Posting Details