Use the skeleton code attached below to create a proxy between two warehouses. The client is unaware of the two warehouses and only talks to the proxy (Think Amazon.com). The proxy re-routes the...


Use the skeleton code attached below to create a proxy between two warehouses. The client is unaware of the two warehouses and only talks to the proxy (Think Amazon.com). The proxy re-routes the orders to the individual warehouses based on their inventory status. For example, one warehouse may contain an item that the other does not. The proxy checks for this and places the order at the correct warehouse.


Each warehouse has a method called order() which takes the name of the item and the number of items ordered. If it is able to satisfy the order, it returns true, else it returns false.


_______________________________________________________________________________


interface IWarehouse {
boolean order(String name, int count);
}
class Warehouse implements IWarehouse {
private final int MAX_COUNT = 5;
private String[] names;
private int[] counts;
private int current;
public Warehouse() {
names = new String[MAX_COUNT];
counts = new int[MAX_COUNT];
current = 0;
}
public void put(String name, int count) {
if (current == MAX_COUNT)
System.out.println("Warehouse full!!");
else {
names[current] = name;
counts[current] = count;
current++;
}
}
public boolean order(String name, int count) {
for (int i = 0; i

if (names[i].equals(name)) {
if (counts[i] >= count) {
// process order
counts[i] -= count;
return true;
}
else {
// not enough items to process order
return false;
}
}
}
// item not found
return false;
}
}
/// TODO - modify this class so that it has two warehouses
class ProxyWarehouse implements IWarehouse {
@Override
public boolean order(String name, int count) {
return false;
/// TODO - change this method so that it checks both warehouses for the item
// and returns if one is available in either one of them
}
}
public class ProxyMain
{
public static void main(String[] args)
{
/// TODO - 1. Create 2 warehouses and then add some items in each of the them.
/// TODO - 2. Create a ProxyWaarehouse with the 2 warehouses created in 1
/// TODO - 3. Order a few items from the ProxyWarehouse. Make sure the proxy does not contain any items itself
// and all orders are satisfied from the underlying Warehouse objects.
}
}

Nov 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here