Question: Write a program to pack boxes with blobs. Write two classes and a driver program. A Blob class implements the following interface. (Defines the following

Write a program to pack boxes with blobs. Write two classes and a driver program.

A Blob class

implements the following interface. (Defines the following methods.) public interface BlobInterface { /** getWeight accessor method. @return the weight of the blob as a double */ public double getWeight(); /** toString method @return a String showing the weight of the Blob */ public String toString(); }

A Blob must be between 1 and 4 pounds, with fractional weights allowed.

A default constructor creates a Blob with a weight of 2 pounds.

A one-double-parameter constructor creates a Blob with that many pounds, or throws an IllegalArgumentException if the weight is less than 1 or greater than 4 pounds.

A Box class

implements the following interface. (Note that, since the Blob class implements BlobInterface, then a Blob is a BlobInterface, so a Blob can be passed to the insert method below.) public interface BoxInterface { /** insert inserts a Blob into the box @param b the Blob to insert @return true if the blob fits, or false if it doesn't */ public boolean insert(BlobInterface b); /** remainingCapacity accessor method @return the remaining capacity of the box (how many more pounds it can hold). */ public double remainingCapacity(); /** toString @return a String listing all of the Blobs in the Box, followed by the total weight */ public String toString(); }

A default constructor gives a Box capable of holding up to 25 pounds of Blobs.

An one-int-parameter constructor creates a Box capable of holding that number of pounds, but throws an IllegalArgumentException for 0 or negative arguments.

The driver program should

Instantiate 5 25-pound-capacity Boxes and

30 Blobs with weights that are random doubles from 1 to 4 (Math.random()*3+1).

Put the 30 Blobs into the boxes, filling the first box, then the second, etc., and then printing out each box.

Every Blob that is instantiated must be inserted into a Box.

The driver may be a console or GUI application.

Note that the driver program might not use some of the methods or constructors. You should define them anyway. Also, use ArrayLists rather than arrays.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!