CS 149: Programming Fundamentals
James Madison University, Spring 2017 Semester

PA6: Boxes in Boxes (Classes and Objects)

Part A (10 pts): Due Friday, Apr 14 at 11:59 PM

Readiness quiz on Canvas.

Late work will not be accepted. If you do not submit by Fri, Apr 14th at 11:59 PM, you will receive a zero for Part A.

Part B (30 pts): Due Monday, Apr 17 at 11:59 PM

Flirtey Drone Delivery

Submit only your JUnit tests (BoxTest.java and WarehouseTest.java) via Web-CAT.

Late work will not be accepted. If you do not submit by Mon, Apr 17th at 11:59 PM, you will receive a zero for Part B.

Part C (60 pts): Due Friday, Apr 21 at 11:59 PM

Submit Box.java, Warehouse.java, and your revised test cases via Web-CAT.

  • -25% on Sat, Apr 22 by 11:59 PM
  • -50% on Sun, Apr 23 by 11:59 PM
  • Not accepted afterwards

You may (and should) revise your test cases in your final submission.

Objectives

  • Implement a specific design from UML diagrams.
  • Validate the arguments before updating an object.
  • Write toString methods that use string formatting.
  • Solve problems using object-oriented techniques.

Honor Code

This assignment should be viewed as a take-home exam and must be completed individually. Your work must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 149/159, and the instructor. Copying work from another student or the Internet is an Honor Code violation and will be grounds for a reduced or failing grade in the course.

Background

Dukes Shipping is an experimental drone delivery service that provides package delivery services via drones. We will only ship containers via drones that are already in boxes, our drones can only carry certain size boxes, and we provide outer protective boxes and packing material to protect those contents. Dukes Shipping maintains a warehouse of boxes in which a drone will ship the customer's package. When a customer comes in, the clerk must measure the customer's box and then decide whether or not there is a drone delivery box into which the customer's box can be placed. If so, we can ship the package. If not, we must turn the customer away. It is important that we match the drone boxes to the customer's box as closely as we can. If we waste a large container with a small box, we potentially could lose a sale. Your application will help the sales clerk find the drone shipping box that best fits the customer's box.

Requirements

In this assignment, you will design and implement a program that populates a Warehouse with Boxes, and allows individual Boxes to be shipped. Your program must be built using the following classes:

  • Boxes.java - This class is provided for you.
  • DukesShipping.java - This class is provided for you.
  • Box.java - You must write this class from scratch.
  • Warehouse.java - You must write this class from scratch.

You actually don't need the first two files; they are simply provided to show how your classes might be used in a larger application. The following UML diagram illustrates the relationship of the classes to one another.

Boxes UML

Each box is identified by its dimensions (length, width, and depth). In order to ship a box, you must get its dimensions to determine which drone box in the warehouse is the "best" box in which to ship it. The best drone box is the one with the smallest volume that is large enough to contain the box to be sent.

Attributes and Methods

Box.java

MIN_SIZE: double - This class constant is set to 2.0.

Box(double length, double width, double depth): The Box constructor takes in the three dimensions. Any dimensions less than MIN_SIZE must be changed to MIN_SIZE.

Box(Box other): This copy constructor takes in a Box object and initializes the new Box to the same dimensions.

equals(Object obj): Returns true if this Box has the same length, width, and depth as the given object. (This method is necessary for assertEquals to work in your test cases.)

toString: This method must return the string "lengthxwidthxdepth" where length, width, and depth are the dimensions of the box formatted to two decimal places.

willFit: This method must return true if the "other" box will fit inside "this" box. That means that each of the dimensions in the other Box must be less than the corresponding dimension of this Box. Note that boxes can be rotated. For example, a box that is 16.50x11.99x15.00 would fit inside a 18.00x18.00x12.00 box.

Warehouse.java

Your warehouse must support three standard drone delivery box sizes: 36.00x24.00x18.00 for Big, 18.00x18.00x12.00 for Medium, and 4.00x4.00x6.00 for Small.

Warehouse(int, int, int): The Warehouse constructor takes in the count of each of the types of boxes that the warehouse can hold. If a count is less than 0, the constructor must make it 0.

findBox: This method must find the smallest Box in the warehouse that can "hold" the parameter Box. For example, if we want to ship an item that is 3.50x3.50x5.00 we would normally use the Small box. But if there are no more Small boxes, then we need to move to the Medium box. If the item is too large for any box or there are no more boxes left, then this method should return null. NOTE: This method must return a copy of BIG_BOX, MEDIUM_BOX, or SMALL_BOX (or null). Be sure to decrement the appropriate box count before returning.

toString: This method should return a String with the following three lines:

Big Boxes lengthxwidthxdepth: #
Medium Boxes lengthxwidthxdepth: #
Small Boxes lengthxwidthxdepth: #

where # is replaced by the number of that kind of box and the lengthxwidthxdepth is replaced by the Box string. Note that the first character of the output is the B in "Big" and the output string will end with the third newline character. (There are no blank lines between each line of output.) There is a space between the ':' and the count. The format must be exactly right.

Hints and Tips   UPDATED!

  • Work out your willFit method on paper using a large number of different box sizes. Test your willFit method via JUnit using a large number of different box sizes.

  • Do not implement any other methods than what you see in the UML diagram. For example, you should not have a Box.rotate() method, even for testing purposes.

  • Do not use any static/instance variables in your test classes. JUnit will run your test methods in a random order, so only use local variables to avoid corrupting test data.

  • Make sure you're using the required constants Box.MIN_SIZE, Warehouse.BIG_BOX, etc. Your test code should not use magic numbers like 2.0 or 36.0.

  • JUnit's assertEquals method automatically calls the object's equals method. So instead of writing assertTrue(box1.equals(box2)), you should just write assertEquals(box1, box2).

  • To implement the Box.equals method, you'll need to use the instanceof operator. For example:

    if (obj instanceof Box) {
        Box box = (Box) other;
        ...
    }
    

Back to Top