Question: Java... Now we must give the Warehouse class some of the functionality that all warehouses need: a systematic way to store and keep track of
Java...
Now we must give the Warehouse class some of the functionality that all warehouses need: a systematic way to store and keep track of products when they arrive in the warehouse, and a systematic way to gather together everything that is to be shipped out when an order is received. Here, we ask you to define a receive method that performs the first of these tasks. Then, in the optional part of this lab, we explain how to define a ship method that will perform the second.
Here's what the receive method needs to do:
It takes two inputs: a Footwear object and a positive integer that specifies how many units of that product are arriving.
It checks to see if the incoming product is already listed in myCatalog and, if not, adds it to the catalog.
Next, it locates the bin that contains the smallest total quantity. (If there are any bins in the warehouse that are empty, then the first one it locates will serve as the one with the most available space.) If all the bins are full, it adds a new empty bin, which will then automatically become the next bin to use.
Then it adds as many units of the incoming product to the chosen bin as possible before either there is no more incoming product left to be placed in a bin or the bin becomes full to capacity, myBinMax.
Finally, if there remains some unplaced incoming product, it returns to Step 3 above.
Add the definition of a receive method that behaves in the above manner to your Warehouse class definition.
Class with Main:
public class Lab
{
public static int random( int n )
{
return (int)( n * Math.random() );
}
public static ArrayList
{
String[][] styles =
{
//Boot styles
{ "Cowboy", "Hiking", "Rain", "Riding" },
// Dress shoe styles
{ "Loafer", "Oxford", "Pump", "Sling-back", "Wing-tip" },
// Casual shoe styles
{ "Athletic", "Hightop", "Moccasin", "Sandal" }
};
double[] sizes = { 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5,
10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14 };
ArrayList
Footwear fw;
for ( int i = 0; i < n; i++ )
{
int fwType = random( styles.length );
String[] styleList = styles[ fwType ];
String style = styleList[ random( styleList.length ) ];
double size = sizes[ random( sizes.length ) ];
String sku = "1234-" + i;
if ( fwType == 0 )
fw = new Boot( style, size, sku );
else if ( fwType == 1 )
fw = new DressShoe( style, size, sku );
else
fw = new CasualShoe( style, size, sku );
catalog.add( fw );
}
return catalog;
}
public static String lookupFootwear( ArrayList
{
for ( Footwear fw : catalog )
{
if (fw.getSKU().equals(sku) )
return fw.toString();
}
return "SKU " + sku + " not in catalog";
}
public static void main( String[] args )
{
Warehouse w = new Warehouse( 10 );
Footwear d0 = new DressShoe( "Loafer", 10.5, "1234-13" );
Footwear b = new Boot( "Riding", 8, "1234-5" );
Footwear c = new CasualShoe( "Sandal", 9.5, "1234-0" );
Footwear d1 = new DressShoe( "Wing-tip", 10, "1234-3" );
w.receive( d0, 4 );
w.receive( b, 25 );
w.receive( c, 18 );
w.receive( d1, 5 );
System.out.println( w );
}
}
------------------------Need assistance writing receive method in Warehouse Class--------------------------------------
public class Warehouse
{
private int myBinMax;
private ArrayList
private ArrayList
public Warehouse( int binMax )
{
myBinMax = binMax;
myCatalog = new ArrayList
myBins = new ArrayList
for ( int i = 0; i < 5; i++ )
addBin();
}
public void addBin()
{
myBins.add( new Bin( "B" + myBins.size() ) );
}
public String toString()
{
String s = "";
for ( Bin bin : myBins )
{
if ( s.length() > 0 )
s += " ";
s += "Bin " + bin.getName() + ":";
for ( BinItem item : bin.getContents() )
{
s += " " + Lab04Runner.lookupFootwear( myCatalog,
item.getSKU() )
+ ", " + item;
}
}
return s;
}
public void receive(Footwear object, int a) {
if (!myCatalog.contains(object)) {
myCatalog.add(object);
}
.etc .etc
--------- Output Reqested ------------
Bin B0: Dress Shoe Loafer (size 10), SKU 1234-13: 4 Casual Shoe Sandal (size 9), SKU 1234-0: 6 Bin B1: Boot Riding (size 8), SKU 1234-5: 10 Bin B2: Boot Riding (size 8), SKU 1234-5: 10 Bin B3: Boot Riding (size 8), SKU 1234-5: 5 Casual Shoe Sandal (size 9), SKU 1234-0: 2 Dress Shoe Wing-tip (size 10), SKU 1234-3: 3 Bin B4: Casual Shoe Sandal (size 9), SKU 1234-0: 10 Bin B5: Dress Shoe Wing-tip (size 10), SKU 1234-3: 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
