Problem Statement
Calculate how much it would cost to ship a box given its weight and dimensions. The shipping service charges rate dollars for each pound that a package weighs. However, if a package weighs less than thresholdWeight pounds and its (length + girth) is greater than thresholdSize inches, it is billed as a package that weighs thresholdWeight pounds. The length of a box is its longest side. The girth is the distance around the box perpendicular to the length. In other words, if the two non-length sides are called width and height, girth is defined as width + height + width + height. If a box has two equal sides that are greater than the third side, or if a box has three equal sides, any of the multiple longest sides can be used as the length.
The dimensions of the box are given as a String formatted as "<side>x<side>x<side>" (quotes for clarity only), where each <side> is a positive integer with no leading zeros. All lengths are given in inches, and all weights are given in pounds.
Definition
- Class:
- ShippingCost
- Method:
- getCost
- Parameters:
- String, int, int, int, int
- Returns:
- int
- Method signature:
- int getCost(String dimensions, int weight, int rate, int thresholdSize, int thresholdWeight)
- (be sure your method is public)
Constraints
- dimensions will be formatted as "<side>x<side>x<side>" (quotes for clarity only), where each <side> is an integer between 1 and 100, inclusive, with no leading zeros. Each 'x' is lowercase.
- weight will be between 1 and 100, inclusive.
- rate will be between 1 and 10, inclusive.
- thresholdSize will be between 20 and 300, inclusive.
- thresholdWeight will be between 30 and 100, inclusive.
Examples
"10x4x5"
50
2
25
75
Returns: 150
The length of this box is 10 and the girth is 4 + 5 + 4 + 5 = 18. Since (length + girth) = 28, which is greater than thresholdSize, and the box weighs less than thresholdWeight pounds, it is treated as a package that weighs thresholdWeight pounds. The shipping cost is therefore 75 * 2 = 150."5x4x10"
50
2
28
75
Returns: 100
The (length + girth) of this box is exactly equal to thresholdSize, so the cost is simply 50 * 2 = 100."100x100x100"
99
10
300
100
Returns: 1000
The (length + girth) of this box is 500, which is greater than thresholdSize, and its weight is less than thresholdWeight. The shipping cost is therefore 100 * 10 = 1000."100x100x100"
100
10
30
70
Returns: 1000