Created
January 25, 2016 03:36
-
-
Save darinthompson/0ba2ce4718afb4f7dad3 to your computer and use it in GitHub Desktop.
adding functionality to script. Wondering why it repeats the gets.chomp and gives weird answer.
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
require 'date' | |
class PerDiem | |
attr_accessor :start_date, :end_date, | |
def initalize(start_date, end_date, per_diem) | |
@start_date = start_date | |
@end_date = end_date | |
@per_diem = per_diem | |
end | |
def get_dates | |
puts "Insert dates. (dd/mm/yyyy)" | |
puts "starting date..." | |
@start_date = Date.parse(gets.chomp) | |
puts "ending date..." | |
@end_date = Date.parse(gets.chomp) | |
end | |
def number_of_days | |
(@end_date - @start_date).to_i | |
end | |
def amount_of_per_diem | |
puts "Per Diem Rate..." | |
@per_diem = gets.chomp | |
if number_of_days > 180 | |
@per_diem = @per_diem * 0.55 | |
elsif number_of_days < 30 && number_of_days < 90 | |
@per_diem = @per_diem * 0.75 | |
else | |
@per_diem | |
end | |
end | |
def display_number_of_days | |
puts "-" * 40 | |
puts "Number of days: #{number_of_days}" | |
end | |
def calculate_per_diem | |
@per_diem * number_of_days | |
end | |
def display_per_diem | |
puts "-" * 40 | |
puts "Amount of Per Diem Earned: #{calculate_per_diem}" | |
end | |
end | |
darin = PerDiem.new | |
darin.get_dates | |
darin.number_of_days | |
darin.display_number_of_days | |
darin.amount_of_per_diem | |
darin.calculate_per_diem | |
puts "Per Diem rate: " + darin.amount_of_per_diem.to_s | |
darin.display_per_diem | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment