Last active
June 22, 2016 17:44
-
-
Save jeffwolfram/cb72b4301feaf1adb55c7888ec2b3c6f to your computer and use it in GitHub Desktop.
Employee payroll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
attr_reader :name | |
def name=(name) | |
end | |
def print_name | |
puts "Name: #{name}" | |
end | |
end | |
class SalariedEmployee < Employee | |
attr_reader :salary | |
def salary=(salary) | |
#code to validate and set @salary | |
end | |
def print_pay_stub | |
print_name | |
pay_for_period = (salary / 365.0) * 14 | |
formatted_pay = format("$%.2f", pay_for_period) | |
puts "Pay this period: #{formatted_pay}" | |
end | |
end | |
class HourlyEmployee < Employee | |
attr_reader :hourly_wage, :hours_per_week | |
def hourly_wage=(hourly_wage) | |
#code to validate and set @hourly_wage | |
end | |
def hours_per_week=(hours_per_week) | |
#code to validate and set @hours_per_week | |
end | |
def print_pay_stub | |
print_name | |
pay_for_period = hourly_wage * hours_per_week * 2 | |
formatted_pay = format("$%.2f", pay_for_period) | |
puts "pay This Period: #{formatted_pay}" | |
end | |
end | |
hourly_employee = HourlyEmployee.new | |
hourly_employee.name = "Amy" | |
hourly_employee.hourly_wage = 14 | |
hourly_employee.hours_per_week = 30 | |
hourly_employee.print_pay_stub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment