Program which calculates earnings (with some difficulties)..

  • Thread starter Joop Van den tillaart
  • Start date
J

Joop Van den tillaart

Hi you all,

I have a 'problem' which I cannot solve using spreadsheet software like
Excel.

The problem involves some little program I want to make which can
calculate my earnings of a days work by just inserting the time I start
working and the time I stop working. Because I work with different
earning percentages during a day this isn't as easy as it sounds (at
least not for me). I tried some different approaches in Excel but
couldn't get it to work the way I wanted it to.

I had a project once with some work done in Ruby (mostly NOT done by me
so I'm not a pro at Ruby :D) and now I thought maybe you Ruby experts
can come up with an idea to get this done.

Here are the percentages:

Hours between: 00:00 - 05:00 = earnings per hour * 1.85 (night shift)
Hours between: 05:00 - 07:00 = earnings per hour * 1.35 (early morning
shift)
Hours between: 07:00 - 16:00 = earnings per hour * 1.00 (day shift)
Hours between: 16:00 - 18:00 = earnings per hour * 1.35 (late afternoon
shift)
Hours between: 18:00 - 00:00 = earnings per hour * 1.60 (evening shift)

An extra dimension to the problem is added because of the fact that
after each 4 hours I work, half an hour (work break) of the earnings per
hour * percentage (percentage of the 4 hours worked) is not being paid.
So these unpaid breaks are also variable in percentage.

I need a solution where I can input my starting time and ending time and
which calculates my earnings during these hours (working day). Also I
(or the program ;-)) need(s) to be able to put in different starting
times and ending times because I work with a very variable/fluctuating
working schedule...

Maybe it's a long story but I hope you guys understand what I mean and
maybe some of you experts see a way of how to do this in Ruby. Please
let me know then and I would be higly grateful!!

Thanks in ADVANCE!!!

Greets, tillaart36!
 
J

James Edward Gray II

I have a 'problem' which I cannot solve using spreadsheet software
like
Excel.

Neat problem.

Are you wanting us to solve it for you, or help you solve it? I'll
hope it's the latter and try doing that.

The biggest secret to programming is to work in small slices. Break
the problem down as much as you can and then just keep adding bit by
bit until you reach the goal.

So, I'm thinking these are some good steps to work in:

1. Write a program that accepts a start and end time from you and
just prints them to the screen. You could possibly take these in as
command-line arguments or you could prompt the user for input.
2. Modify your program to print the total number of hours between
the entered start and end time. This is a little trickier than
simple subtraction, since you could start working on one day and end
on a different day.
3. Modify your program to divide this total hour count down into the
various shifts. So instead of telling you that you worked five
hours, it would tell you that you worked four night shift hours and
one morning shift hour.
4. Modify your program to remove the half hour breaks as they
occur. Make sure this drops out of the proper shift hours, so the
pay will be adjusted correctly.
5. Modify your program to print money earned, instead of hours.
This step is now just simple math.

Hope that helps. Please do ask us for ideas when you get stuck!

James Edward Gray II
 
J

Joop Van den tillaart

James said:
Neat problem.

Are you wanting us to solve it for you, or help you solve it? I'll
hope it's the latter and try doing that.

Okay it's a little bit of both...I'm not asking for a total solution on
the one hand but on the other hand...I have very little expiernce in
programming let alone in working with ruby...So it will be very hard for
me to come with a (pretty) detailed piece of program which has to be
tweaked to do what I want.

Hower thanks very much for your reply and I hope others (or you
yourself) take the time to think about this problem and come with ideas
or small pieces of code.

For now I'll dive into your ideas and I am looking forward to other
ideas and/or input from the people on this forum!

Thanks!
 
J

Jeremy Woertink

Not sure if you still need this, but if so, then this should give you a
boost in the right direction.

NIGHT_SHIFT = "00:00".."05:00"
EARLY_SHIFT = "05:01".."07:00"
DAY_SHIFT = "07:01".."16:00"
LATE_SHIFT = "16:01".."18:00"
EVENING_SHIFT = "18:01".."23:59"

def get_pay_rate(time, earnings)
@payrate = earnings * 1.85 if NIGHT_SHIFT.include?(time)
@payrate = earnings * 1.35 if EARLY_SHIFT.include?(time)
@payrate = earnings * 1.00 if DAY_SHIFT.include?(time)
@payrate = earnings * 1.35 if LATE_SHIFT.include?(time)
@payrate = earnings * 1.60 if EVENING_SHIFT.include?(time)
return @payrate
end

# Start program
puts "Payrate calculator"
puts "Enter a starting time (i.e. 13:00 or 01:59)"
start_time = Time.parse(gets.chomp)

puts "Enter ending time in the same format."
end_time = Time.parse(gets.chomp)

puts "How much do you make?"
earnings = gets.chomp

daily_pay = Array.new

(start_time.hour..end_time.hour).each do |time|
daily_pay << get_pay_rate((time.to_s.rjust(2, "0") << ":00"),
earnings)
end


~Jeremy
 
J

Jeremy Woertink

WOW! yeah, totally forget what I just posted.


note to self: testing is a good idea!


haha. I guess that's what I get for just writing blindly :)



sorry,

~Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top