Skip to content

Instantly share code, notes, and snippets.

@jmoon90
Last active December 30, 2015 01:09
Show Gist options
  • Select an option

  • Save jmoon90/7754754 to your computer and use it in GitHub Desktop.

Select an option

Save jmoon90/7754754 to your computer and use it in GitHub Desktop.
require_relative 'tax_calculation'
record_list =
[
{
first_name: 'Johnny',
last_name: 'Smith',
annual_income: 120000,
tax_paid: 28000
},
{
first_name: 'Liz',
last_name: 'Lemon',
annual_income: 95000,
tax_paid: 21000
},
{
first_name: 'Jane',
last_name: 'Doe',
annual_income: 140000,
tax_paid: 30000
},
{
first_name: 'Mike',
last_name: 'Orsillio',
annual_income: 40000,
tax_paid: 8800
}
]
tax = TaxCalculation.new(record_list)
tax
class TaxCalculation
def initialize(record_list)
@record_list = record_list
liability
end
def liability
@record_list.each do |individual|
individual[:tax_owed] = (individual[:annual_income] * 0.22).to_i
output_message(individual, "has a tax liability of")
refund(individual)
end
end
def refund(individual)
individual[:tax_owed] = (individual[:tax_owed] - individual[:tax_paid])
tax = individual[:tax_owed]
if tax < 0
output_message(individual, "will receive a refund of")
elsif tax > 0
output_message(individual, "still owes" )
else
output_message(individual, "receives and owes nothing")
end
end
def output_message(individual, message)
puts "#{individual[:first_name]} #{individual[:last_name]} #{message} #{individual[:tax_owed].abs}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment