TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

Paycheck

Problem statement, definition, constraints, and public examples.

Problem Statement

Jim is paid $10 an hour with a few exceptions. He earns an extra $1.50/hour for
any part of a day where he works more than 8 hours, and an extra $2.50/hour for
hours beyond 40 in any one work week (only counting M-F hours). Also,he earns a
125% bonus for working on Saturday and a 50% bonus for working on Sunday,
applied after all other calculations. The bonuses for Saturday and Sunday are
computed based on the hours worked those days; they are *not* used to calculate
any bonus for working more than 40 hours in a week (though they do earn the
extra $1.50/hour for working more than 8 hours).

Create a class Paycheck that includes the method solve(), which takes an int[]
of seven elements representing the hours worked each day, beginning with
Sunday. Each input must be in the range 0 to 24, inclusive. The output will be
a double rounded to two digits using the included formatDouble() method. Simply
pass your solution through this method before returning to ensure the correct
format. Here is the method signature:

// Precondition: input is an int[] of size 7, holding Integers representing the
hours worked each day, starting with Sunday.
// Postcondition: returns the paycheck for that week, a double formatted to 2
decimal places.
public double solve(int[] input);

Examples:
[0, 8, 9, 8, 8, 8, 0] -> 414.0 (the second zero will get truncated. Don't worry
about that)
[6, 8, 13, 9, 11, 12, 2] -> 717.0
[9, 8, 8, 6, 7, 8, 10] -> 739.0

Definition

Class:
Paycheck
Method:
solve
Parameters:
int[]
Returns:
double
Method signature:
double solve(int[] param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems