# Hourly Wage Calculator using Java Assignment Solution

## Calculate wage based on hours worked

Summary

Write a java homework that will calculate two weeks of hourly pay for an individual. Payment will depend on the actual hours worked, overload, and the week of the year the hours were worked. The results will be displayed to the user.

Overall Requirements

• From the user, get the number of the week worked.
• From the user, get the hours worked for the week. The user should enter seven double values.
• The standard pay rate is \$15.00 / hour.
• Overtime pay is 1.5 times the standard pay, for hours worked over 40 hours per week.
• High demand pay is an additional \$2.00 / hour or \$17.00 / hour.
• High demand pay will be calculated for Weeks 1, 2, 44-54.
• Allow users to calculate wages for another week.

Functional requirements:

• Declare the following constant variables to utilize in your program:

o HOUR_RATE, double, equal to 15.00

o BONUS_RATE, double, equal to 2.00

o OVERLOAD_PERCENT, double, equal to 1.5

o REGULAR_HOURS, double, equal to 40.0

• Validate the week entered (the week should be between 1 and 54). If a user enters an invalid week, output a short message and ask them to enter a week number again.
• An invalid week should produce a short error “Week must be between 1 and 54, please try again.”
• The system will loop until a valid value is entered. If the user enters -1, the program should end.
• Validate the hours entered for the week.
• If the user enters more or less than 7 values, instruct the user to try again.
• If the user enters non-numeric values, instruct the user to try again.
• If the user enters a negative value or a value greater than 15, instruct the user to try again.
• Calculate the payment for the week.
• Add the number of hours worked for the week.
• Up to 40 hours will be calculated using the base rate.
• Hours over 40 will be calculated using the overtime pay of 1.5. For example, if a person works 45 hours, 40 would be calculated at the base rate, and 5 will be calculated at the overtime rate.
• If the week worked is a high-demand week (1,2, 44-54), add \$2.00 to the base rate.

o A year has 54 weeks, Week 1 is the first week of January, Week 54 is the last week of the year.

• Display the total pay for the week in USD with 2 decimals.
• Display a breakdown of the payment.

o The total regular hours worked, and the rate applied.

o The total of the base rate pay.

o The total of overtime hours worked, and the overtime rate applied.

o The total of the overtime pay.

• Allow the user to enter hours for another week.

Organizational requirements:

• The main method should help as your focus to control the algorithm.
• Your code should use multiple methods to delegate the work that has to be done.

o main(): should control the overall program, a starting java file is provided.

o getInputFromUser() should take as a parameter a Scanner variable and an integer value for the week number. The method should return an array of type double. This method will ask the user to input the hours of work for the week, call the validateInput() method. The method should continue to ask the user as long as the validateInput() method returns false. Once the values are found to be valid, the method should call convertStringArrayToDouble() to get an array containing all the valid values.

o validateInput() should take as a parameter an array of type String, and return a boolean indicating whether the input is valid (true) or not (false). This method should validate that all the values meet the conditions, if any invalid condition is found, the method returns false. If all values are valid, the method returns true.

o convertStringArrayToDouble() should take as a parameter an array of type String, and return an array of type boolean. The method will take each value in the string array, convert it to double, and put it into the numeric array.

o calculatePayForWeek() should take as a parameter an integer value for the week, and an array of type double; the method does not return any values (void). The method will perform and display all the wage calculations. It should call getTotalHours() to obtain the sum of the hours worked. This method should use if statements to identify the different conditions (regular, overtime, and bonus)

o getTotalHours() should take as a parameter an array of type double and return an integer value equal to the sum of all the hours worked.

• Follow all coding style guidelines presented thus far (arrays, methods, and loops). Remember to place comments in front of sections of code to help you and me understand your code better.

o For example, do not handle all the conditions at once: validate only that you have seven values and test it, then add another one.

o Another example is to only work with hours <= 40 and normal weeks, then add the checks for bonus weeks, then add the check for overtime.

• The math may stump you a bit if you are not fully comfortable with using percentages.
• You will most likely need a combination of if-else statements and loop(s) to generate the appropriate choices and to get the right calculations.
• Rates will vary depending on the user input for the month.

o Declare constant values.

o Use math and string functions.

// * write convertStringArrayToDouble method here

// * write calculatePayForWeek method here

// * write getTotalHours method here

}

Solution: