Question
In original Java code, please create a client class to test OrderProcessor. You will need to create a datagenerator for testing purpose. The current code
In original Java code, please create a client class to test OrderProcessor. You will need to create a datagenerator for testing purpose. The current code I have is below:
CODE :
Products.java:
import java.util.*;
/** * The Product class, along with every subclass was provided by the source noted above, * however, I did modify these classes slightly by adding an ID field in order to * associate each product with the order ID individually. */ abstract class Product { protected float price; protected String ID;
// return the price of a particular product abstract float price(); // return the order ID of a particular product abstract String ID(); }
//------------------------------------------------------------
class ComputerPart extends Product { public ComputerPart(String orderID, float p) { price = p; ID = orderID; }
public float price() { return price; } public String ID() { return ID; } }
class Motherboard extends ComputerPart { protected String manufacturer; public Motherboard(String ID, String mfg, float p) { super(ID, p); manufacturer = mfg; } public String getManufacturer() { return manufacturer; } }
class RAM extends ComputerPart { protected int size; protected String manufacturer; public RAM(String ID, String mfg, int size, float p) { super(ID, 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 ID, String type, int speed, float p) { super(ID, p); this.type = type; this.speed = speed; } public String getType() { return type; } public int getSpeed() { return speed; } }
class Peripheral extends Product { public Peripheral(String orderID, float p) { ID = orderID; price = p; } public float price() { return price; } public String ID() { return ID; } }
class Printer extends Peripheral { protected String model; public Printer(String ID, String model, float p) { super(ID, p); this.model = model; } public String getModel() { return model; } }
class Monitor extends Peripheral { protected String model; public Monitor(String ID, String model, float p) { super(ID, p); this.model = model; } public String getModel() { return model; } }
class Service extends Product { public Service(String orderID, float p) { price = p; ID = orderID; } public float price() { return price; } public String ID() { return ID; } }
class AssemblyService extends Service { String provider; public AssemblyService(String ID, String pv, float p) { super(ID, p); provider = pv; } public String getProvider() { return provider; } }
class DeliveryService extends Service { String courier; public DeliveryService(String ID, String c, float p) { super(ID, p); courier = c; } public String getCourier() { return courier; } }
//------------------------------------------------------- class Cheese extends Product { public Cheese(String orderID, float p) { price = p; ID = orderID; } public float price() { return price; } public String ID() { return ID; } }
class Cheddar extends Cheese { public Cheddar(String ID, float p) { super(ID, p); } } class Mozzarella extends Cheese { public Mozzarella(String ID, float p) { super(ID, p); } }
class Fruit extends Product { public Fruit(String orderID, float p) { price = p; ID = orderID; } public float price() { return price; } public String ID() { return ID; } } class Apple extends Fruit { public Apple(String ID, float p) { super(ID, p); } } class Orange extends Fruit { public Orange(String ID, float p) { super(ID, p); } }
//------------------------------------------------------- /** * Products class, used to hold the main method which calls the client class * to test OrderProcessor functionality */ public class Products { public static void main(String[] args) { ClientTest.testOrder(); ClientTest2.testOrder(); } }
//------------------------------------------------------- //GenericOrder acts as a collection of an arbitrary nnumber of Product types: class GenericOrder { public ArrayList
//GenericOrder constructor: public GenericOrder(String ID) { ArrayList
//Generic class since several subclasses of Product can be added to the order: public
public Product get(int element) { return order.get(element); //gets the element of the order as sent in numerically }
public String getID() { return ID; //returns the order ID }
public int size() { return order.size(); //returns the size of the order } }
//-----------------------------------------------------------------------------------------------------------
//ComputerPartyOrder extends GenericOrder, and can accept all types of Products(from each category): class ComputerPartyOrder extends GenericOrder { //ComputerPartyOrder constructor: public ComputerPartyOrder(String ID) { super(ID); //calls the superclass } }
//-----------------------------------------------------------------------------------------------------------
//ComputerOrder extends GenericOrder, however it can only accept specific types of Products: class ComputerOrder extends GenericOrder { //ComputerOrder constructor: public ComputerOrder(String ID) { super(ID); //calls the superclass }
public void add(Product item) { //overrides the add method in the superclass to only add the correct types of Product to the ComputerOrder: if(item.getClass().getSuperclass().equals(ComputerPart.class) || item.getClass().getSuperclass().equals(Peripheral.class) || item.getClass().getSuperclass().equals(Service.class)) { order.add(item); } else { //if an incorrect item is attempted to be added, this error message is printed and the item is not added: System.out.println("The item you are trying to purchase does not fit within the order type and cannot be added."); } } }
/-----------------------------------------------------------------------------------------------------------
//PartyTrayOrder extends GenericOrder, however it can only accept specific types of Products: class PartyTrayOrder extends GenericOrder { //PartyTrayOrder constructor: public PartyTrayOrder(String ID) { super(ID); //calls the superclass }
public void add(Product item) { //overrides the add method in the superclass to only add the correct types of Product to the PartyTrayOrder: if(item.getClass().getSuperclass().equals(Cheese.class) || item.getClass().getSuperclass().equals(Fruit.class) || item.getClass().getSuperclass().equals(Service.class)) { order.add(item); } else { //if an incorrect item is attempted to be added, this error message is printed and the item is not added: System.out.println("The item you are trying to purchase does not fit within the order type and cannot be added."); } } }
//-----------------------------------------------------------------------------------------------------------
//OrderProcessor uses a variety of organization methods to process and dispatch multiple orders class OrderProcessor { public ArrayList
//OrderProcessor constructor: public OrderProcessor() { ArrayList
public
public ArrayList
//the process method taked in all accepted orders and sorts them into more specific collections: public static void process(ArrayList
//for each order in orderList, each Product in the order is type checked and sorted accordingly: for(int i=0; i //dispatching the orders to the appropriate dispatch methods: dispatchComputerParts(computerList); dispatchPeripherals(peripheralList); dispatchCheeses(cheeseList); dispatchFruits(fruitList); dispatchServices(serviceList); } //Each dispatchXXX method produces output based on the type of items within the collection to be dispatched after type checking through instanceof: public static void dispatchComputerParts(ArrayList There are 3 Steps involved in it See step-by-step solutions with expert insights and AI powered tools for academic successStep by Step Solution
Step: 1
Get Instant Access to Expert-Tailored Solutions
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started