Hi,

I need help with an assignment for a class I'm taking. The assignment requirements are as follows:
1.Carefully study the class structure in Products.java.
Here is Products.java:

abstract class Product {
    protected float price;
    // return the price of a particular product
    abstract float price();
}
class ComputerPart extends Product {
    public ComputerPart(float p) {
	price = p;
    }
    public float price() { return price; }
}
class Motherboard extends ComputerPart {
    protected String manufacturer;
    public Motherboard(String mfg, float p) {
	super(p);
	manufacturer = mfg;
    }
    public String getManufacturer() { return manufacturer; }
}
class RAM extends ComputerPart {
    protected int size;
    protected String manufacturer;
    public RAM(String mfg, int size, float p) {
	super(p);
	this.manufacturer = mfg;
	this.size = size;
    }
    public String getManufacturer() { return manufacturer; }
}
class Drive extends ComputerPart {
    protected String type;
    protected int speed;
    public Drive(String type, int speed, float p) {
	super(p);
	this.type = type;
	this.speed = speed;
    }
    public String getType() { return type; }
    public int getSpeed() { return speed; }
}
class Peripheral extends Product {
    public Peripheral(float p) {
	price = p;
    }
    public float price() { return price; }
}
class Printer extends Peripheral {
    protected String model;
    public Printer(String model, float p) {
	super(p);
	this.model = model;
    }
    public String getModel() { return model; }
}
class Monitor extends Peripheral {
    protected String model;
    public Monitor(String model, float p) {
	super(p);
	this.model = model;
    }
    public String getModel() { return model; }
}
class Service extends Product {
    public Service(float p) {
	price = p;
    }
    public float price() { return price; }
}
class AssemblyService extends Service {
    String provider;
    public AssemblyService(String pv, float p) {
	super(p);
	provider = pv;
    }
    public String getProvider() { return provider; }
}
class DeliveryService extends Service {
    String courier;
    public DeliveryService(String c, float p) {
	super(p);
	courier = c;
    }
    public String getCourier() { return courier; }
}
class Cheese extends Product {
    public Cheese(float p) {
	price = p;
    }
    public float price() { return price; }
}
class Cheddar extends Cheese {
    public Cheddar(float p) {
	super(p);
    }
}
class Mozzarella extends Cheese {
    public Mozzarella(float p) {
	super(p);
    }
}
class Fruit extends Product {
    public Fruit(float p) {
	price = p;
    }
    public float price() { return price; }
}
class Apple extends Fruit {
    public Apple(float p) {
	super(p);
    }
}
class Orange extends Fruit {
    public Orange(float p) {
	super(p);
    }
}

2.Design a generic container called GenericOrder that acts as a collection of an arbitrary number of objects in Products.java. Design a mechanism that gives each instance of the container a unique identifier. Implement as many methods as necessary. You must use Java generics features.
3.Design and implement a subclass of GenericOrder called ComputerOrder that takes an arbitrary number of different classes of ComputerPart objects, Peripheral objects, and Service objects. Implement as many methods as necessary.
4.Design and implement a subclass of GenericOrder called PartyTrayOrder that takes an arbitrary number of different classes of Cheese objects, Fruit objects, and Service objects. Implement as many methods as necessary.
5.Design and implement a class called OrderProcessor. You must implement at least the following methods:
accept; // this method accepts a GenericOrder or any of its subclass objects and stores it in any internal collection of OrderProcessor.

process; // this method sorts all accepted orders in the internal collection of GenericOrder into collections of ComputerPart, Peripheral, Cheese, Fruit, and Service. You must associate each object with the unique identifier.

dispatchXXX; // this method simulates the dispatch of the sorted collections. For example, the method dispatchComputerParts() should produce this output:

Motherboard name=Asus, price=$37.5, order number=123456

Motherboard name=Asus, price=$37.5, order number=987654

RAM name=Kingston, size=512, price=$25.0, order number=123456

You may overload each of the above methods as you think necessary.

6.Create a client class to test OrderProcessor. You will need to create a data generator for testing purpose.

This is what I've come up with for number 2:

public class GenericOrder<T> { 
     private static long counter = 1;
     private final long orderNumber = counter++; 
     private List<T> orderItems; 

     public GenericOrder(){
	orderItems = new ArrayList<T>(); 
     }
     public long getOrderNumber() { 
          return orderNumber; 
     } 
     public void addItem(T newItem) { 
	orderItems.add(newItem);
     } 
     public List<T> getItems(){
	return orderItems;
     }
     public void setItems(List<T> orderItems){
	this.orderItems = orderItems; 
     }
}

I'm stuck on number 3, I'm not sure how to get ComputerOrder to take only ComputerPart objects, Peripheral objects, and Service objects. I was thinking of using a bound like

public class ComputerOrder<T extends Product> extends GenericOrder<T> {
     // etc... 
}

However, this still allows Cheese objects and Fruit objects. I've been staring at this for weeks, please help. Thanks.

Uhm, three overloaded methods with <T extends ComputerPart>, <T extends Peripheral>, and <T extends Service>?

Thanks, I knew I was the answer was going to be straight forward but I just wasn't seeing it for some reason.

This question has already been answered. Start a new discussion instead.