Separate calls or combined inputs

A delivery service bills each consignment in 600 g weight units, rounding any partial unit upward. Each consignment also incurs a fixed fee of 95 cents. For the masses used in this question, this Java class implements that pricing rule:


Java
public class DeliveryPrice {
    public static int weightUnits(int grams) {
        return (grams + 599) / 600;
    }

    public static int charge(int grams) {
        return 95 + 145 * weightUnits(grams);
    }

    public static int combinedCharge(int firstGrams,
                                     int secondGrams) {
        return charge(firstGrams + secondGrams);
    }
}


Java integer division discards the fractional part. Two items have masses of 2750 g and 850 g. Assume combining them adds no packaging mass and is permitted by the service.


Find these four quantities as exact integers:

  • The total billed weight units when the items are sent as two separate consignments.
  • The total charge in cents for those separate consignments, calculated using two calls to DeliveryPrice.charge.
  • The billed weight units when both items are sent as one combined consignment.
  • The combined charge in cents returned by DeliveryPrice.combinedCharge(2750, 850).
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Static Keyword and Class Methods Questions: