Class ShippingRule

java.lang.Object
data.ShippingRule

public class ShippingRule extends Object
The ShippingRule class represents a rule for shipping packages based on their dimensions and weight. Each rule specifies the maximum length, width, height, weight, and optionally girth of a package that can be shipped according to this rule, as well as the cost for shipping such a package. It also provides a method to check if a given Packet matches the rule.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final double
    Retrieves the cost for shipping a package according to this rule.
    final Integer
    Retrieves the maximum girth of a package that can be shipped according to this rule.
    final int
    Retrieves the maximum height of a package that can be shipped according to this rule.
    final int
    Retrieves the maximum length of a package that can be shipped according to this rule.
    final int
    Retrieves the maximum weight of a package that can be shipped according to this rule.
    final int
    Retrieves the maximum width of a package that can be shipped according to this rule.
    final String
    Retrieves the type (name) of the package according to this shipping rule, e.g., "Small" or "Large".
    boolean
    Checks if the given packet matches this shipping rule (i.e., fits within the dimensions and weight limits).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShippingRule

      public ShippingRule()
  • Method Details

    • getType

      public final String getType()
      Retrieves the type (name) of the package according to this shipping rule, e.g., "Small" or "Large".
      Returns:
      the shipping rule type as a String
    • getCost

      public final double getCost()
      Retrieves the cost for shipping a package according to this rule.
      Returns:
      the shipping cost as a double
    • getMaxLength

      public final int getMaxLength()
      Retrieves the maximum length of a package that can be shipped according to this rule.
      Returns:
      the maximum length as an int
    • getMaxWidth

      public final int getMaxWidth()
      Retrieves the maximum width of a package that can be shipped according to this rule.
      Returns:
      the maximum width as an int
    • getMaxHeight

      public final int getMaxHeight()
      Retrieves the maximum height of a package that can be shipped according to this rule.
      Returns:
      the maximum height as an int
    • getMaxWeight

      public final int getMaxWeight()
      Retrieves the maximum weight of a package that can be shipped according to this rule.
      Returns:
      the maximum weight as an int
    • getMaxGirth

      public final Integer getMaxGirth()
      Retrieves the maximum girth of a package that can be shipped according to this rule.
      Returns:
      the maximum girth as an int
    • matches

      public boolean matches(Packet pack)
      Checks if the given packet matches this shipping rule (i.e., fits within the dimensions and weight limits). Also respecting the optional girth limit if present.
      Parameters:
      pack - the packet to check
      Returns:
      true if the packet matches this rule, false otherwise