public class Worker
1: //Worker.java
3: /**
4: * This Worker class definition "encapsulates" our idea of a worker by
5: * providing definitions for the "attributes" and "behavior" of a worker.
6: * It implements the PayInterface, which requires an implementation of
7: * the getGrossWage() method.
8: * @author P. Scobey
9: * @version Version 2.0 February 14, 2004
10: */
11: public class Worker
12: implements PayInterface
13: {
14: protected String nameOfWorker;
15: protected double hoursWorked;
16: protected double rateOfPay;
19: /**
20: * Non-default constructor.
21: * Constructs a worker with the name supplied as parameter.
22: */
23: public Worker(String name)
24: {
25: nameOfWorker = name;
26: }
28:
29: /**
30: * An accessor function to retrieve the name of the worker.
31: * @return Reference to the name of the worker
32: */
33: public String getName()
34: {
35: return nameOfWorker;
36: }
39: /**
40: * Sets the number of hours worked by a worker.
41: * @param hours Number of hours worked in a week
42: */
43: public void setHoursWorked(double hours)
44: {
45: hoursWorked = hours;
46: }
49: /**
50: * Sets the rate of pay for a worker.
51: * @param rate Rate of pay in dollars and cents per hour
52: */
53: public void setRateOfPay(double rate)
54: {
55: rateOfPay = rate;
56: }
59: //This is the method whose implemenation is required in order
60: //that the PayInterface be implemented.
61: /**
62: * Gets the gross weekly wage of a worker.
63: * @return The weekly wage of the worker in dollars and cents.
64: */
65: public double getGrossWage()
66: {
67: return hoursWorked * rateOfPay;
68: }
69: }