ATM Program Object Oriented Programming / How to Tutorial

Опубликовано: 18 Март 2026
на канале: RubenOrtega
683
13

Objective
In this assignment you will practice creating a user defined data type including all the needed methods
such as the constructor, getter, setter, and toString methods.
problem
Design a class called Payroll with the following UML diagram. This class is suppose to calculate the salary
of a person. A person can work overtime(more than 40 hours) and the hourly rate for the overtime is
calculated : hourlyRate + hourlyRate * .2
Payroll Class
//list of the instance variables
-name: String
-id : String
-hourlyRate : double
-HoursWorked: double
//list of the methods
+Payroll(String name, String id, double hoursWorked, double hourlyRate) //constructor
+getName() : String
+getId() : String
+getHourlyRate() : double
+getHoursWorked() : double
+setName(String name): void
+setHourlyRate(double rate): void
+setHoursWorked(double hours): void
+getPay() : double
+getRaise(double raiseAmount): void
+getOvertimePay():double
+toString() : String

PayrollDriver class
I have implemented this class and is available to you. Once you implement the Payroll class, you should
be able to run the provided PayrollDriver class.
Once your program is running make sure to add the following to the driver class to get full credit.
1. create two objects of the payroll class (your choice of the attributes)
2. display the objects on the screen by calling the toString method
3. display the salary of each person by calling the getPay method
4. change the hourlyRate of the objects you created
5. display the objects again to see the changes you made by calling the toString method
6. change the hoursworked for the objects you created by calling the setter methods
7. display your objects again to see the changes you made
Requirements
 implement all the methods based on the given description
 No extra attributes/instance variables can be added
 follow the UML and implement all the methods
 Follow the rubric to get full credit
What to turn in
You are going to turn in only one java file that contains two classes(Payroll and PayrollDriver). Turning in
more than one file will not get you the full credit.
Methods description
Constructor
 public Payroll (String name, String id, double hoursWorked, double hourlyRate): accepts the
parameters and initializes the instance variables of the object
Getter methods
 public String getName() : returns the name of the person
 public String getId() : returns the id of the person
 public double getHourlyRate() : returns the hourly rate
 public double getHoursWorked() : returns the number of the hours worked
Setter/mutator methods
 public void setName(String name): changes the name of the person to the given parameter
 public void setHourlyRate(double rate): changes the hourly rate to the given parameter
 public void setHoursWorked(double hours): changes the hours worked to the given parameter
Extra methods
 public double getPay() : calculates the amount that the person is getting paid. If the person
worked less than or equal to 40 hours then pay = hourlyRate * hoursWorked. If the person
worked more than 40 hours then the pay would be: pay = 40 * hourlyRate + (hourseWorked –
40 )* (hourlyRate + hourlyRate * .20)
 public double getOvertimePay(): this method calculates the amount of the money that the
person worked overtime. If the person worked more than 40 hours then the extra pay would be:
(hourseWorked – 40 )* (hourlyRate + hourlyRate * .20). If the person worked less than 40
hours then the overtime pay should be zero
 public void getRaise(double raiseAmount): this method increases the hourlyRate instance
variable by the raise amount: hourlyRate = hourlyRate + raiseAmount; Make sure that the
raiseAmount is not a negative value

toString method
 public string toString() : returns a String representing the attributes for the given person. This
method should create the string in the given format.
Name: Alex Martinez
ID: 123456
Hours worked: 80.0
Hourly Rate: 25.0
Sample output
Creating payroll objects
testing the toString method

Name: Alex Martinez
ID: 123456
Hours worked: 20.0
Hourly Rate: 25.0
Salary is: 500.0
*******************
Name: Ali Santos
ID: 986747
Hours worked: 45.0
Hourly Rate: 125.0
Salary is: 5625.0
*******************
Name: Jose Busta
ID: 45678
Hours worked: 30.0
Hourly Rate: 55.0
Salary is: 1650.0
*******************
Testing the setter methods
The hourly pay of Alex Martinez is being changed
Name: Alex Martinez
ID: 123456
Hours worked: 80.0
Hourly Rate: 25.0