Suppose a class Employee contains: private int hours; // hours worked in the wee
ID: 3621407 • Letter: S
Question
Suppose a class Employee contains:private int hours; // hours worked in the week
private double rate; // hourly pay rate (dollars)
hours and rates are parameters rather than instance variables.That is, supposed the method is specified as
public double pay (int hours, double rate)
Write a definition of a method pay that returns the Employee’s pay for the week, where the Employee is paid the hourly rate for the first 40 hours worked, and paid time and a half for overtime.
Note: It should be a complete specification, including reasonable preconditions and postconditions, for this method.
Explanation / Answer
/* * Function: pay * Precondition: valid number hours (int) and rate (double) passed in. * Postcondition: The total money earned is returned as a double */ public: double pay(int hours, double rate) { if(payRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.