Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this project, you will write a MATLAB program that computes weekly employee e

ID: 3732921 • Letter: I

Question

In this project, you will write a MATLAB program that computes weekly employee earnings assuming a 40-hour work week and pay by the hour. An employee will earn an overtime rate of 1.5 times their normal hourly rate for all hours worked over 40. The program will prompt the user to provide their hourly pay rate and number of hours worked this week. The program output will be the total number of hours worked this week, the pay rate, whether overtime was worked, and the total amount of money earned by the employee that week.

If the user enters a negative value for either hours worked or pay rate, the program will indicate that value cannot be negative and will NOT compute money earned. See the examples at the end of this project description for explicit demonstrations of how the program should behave.

NB: USE MATLAB

EXAMPLE 1

Please enter your hourly pay rate: 10.00

Please enter the number of hours worked: 40

You said you worked 40 hours this week.

Your hourly pay rate is 10.0000.

You worked no overtime this week.

Your total earnings are: 400

EXAMPLE 2

Please enter your hourly pay rate:    10.00

Please enter the number of hours worked:   41

You said you worked 41.0000 hours this week.

Your hourly pay rate is 10.0000

You worked overtime this week.

Your total earnings are: 415.0000

EXAMPLE 3

Please enter your hourly pay rate: 15.10

Please enter the number of hours worked: -10

            How can you work negative hours?

            Program aborted!

EXAMPLE 4

Please enter your hourly pay rate:   - 5.00

            It is so rare to find an employee who wants to pay to work for us…

            Program aborted!

EXAMPLE 5

Please enter your hourly pay rate: 15.10

Please enter the number of hours worked:

            Sorry! Number of hours worked can’t be empty!

            Program aborted!

EXAMPLE 6

Please enter your hourly pay rate:  

            Sorry! Hourly pay rate can’t be empty!

            Program aborted!

Explanation / Answer

hourlyrate = 0;%the pay rate
hours = 0;%The number of hours worked
pay = 0;%Final answer

hourlyrate = input('Please enter your hourly pay rate: ');
if(hourlyrate <= 0)%Check if valid, if not display error and exit
disp(" It is so rare to find an employee who wants to pay to work for us…")
disp(" Program Aborted!")
return
end

hours = input('Please enter the number of hours worked: ');
if(hours <= 0)%Check if valid, if not display error and exit
disp(" How cana you work for negative hours?")
disp(" Program Aborted!")
return
end

%Print out details, with .4 decimal value precison
fprintf('You said you worked %.4f hours this week. ', hourlyrate)
fprintf('Your hourly pay rate is %.4f ', hours)

if(hours > 40)%Check for overtime
pay = (hours - 40)*1.5*hourlyrate;%Calculate overtime pay first
hours = 40;%Set number of hours to 40 so that we can calculate the rest of the pay later
fprintf('You worked overtime this week .')
else
fprintf('You worked no overtime this week .')
end

pay = pay + (hours*hourlyrate);%Calculate total pay
fprintf('Your total earnings are %.4f ', pay)%Display the pay with 4 decimal precison

Sample Output -

>> Example
Please enter your hourly pay rate: 10
Please enter the number of hours worked: 40
You said you worked 10.0000 hours this week.
Your hourly pay rate is 40.0000
You worked no overtime this week
.Your total earnings are 400.0000
>> Example
Please enter your hourly pay rate: 10
Please enter the number of hours worked: 41
You said you worked 10.0000 hours this week.
Your hourly pay rate is 41.0000
You worked overtime this week
.Your total earnings are 415.0000
>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote