// examples and test class added, test stubs added import java.util.*; // ----------------------------------------------------------------------------- // the entry point for the ordering process class Ordering { Vector /* Order */ open = new Vector(); Vector /* Customer */ customers = new Vector(); // -------------------------------------------- Customer lookup(String name) { return null; } Order openOrder(Customer c) { Order o = new Order(c); open.add(o); return o; } // add an order line to o void addLine(Order o, Product p, int q) { o.addLine(p,q); } // compute the value of the order, write to file int closeOrder(Order o) { return o.value(); } // -------------------------------------------- // Examples and Tests // no examples needed: only one exists (singleton pattern) public static void main(String argv) { } } // ----------------------------------------------------------------------------- // representing a customer class Customer { String name; String address; Customer(String name, String address) { this.name = name; this.address = address; } // -------------------------------------------- // Examples static Customer c1 = new Customer("Jonathan","Northeastern"); static Customer c2 = new Customer("Matthias","Rice"); static Customer c3 = new Customer("Robby","Chicago"); } // ----------------------------------------------------------------------------- // representing an order class Order { Customer c; Vector /* OrderLine */ lines = new Vector(); // -------------------------------------------- Order(Customer c) { this.c = c; } // add a line for p and q to the order void addLine(Product p, int q) { lines.add(new OrderLine(p,q)); } // compute the value of the order int value() { return 10; } // ---------------------------------------------- // Examples and Tests static Order o1 = new Order(Customer.c1); public static void main(String argv) { // populate order o1.addLine(Product.p1,10); o1.addLine(Product.p2,2); o1.addLine(Product.p2,1); } } // ----------------------------------------------------------------------------- // representing an orderline class OrderLine { Product p; int q; int value; // -------------------------------------------- OrderLine(Product p, int q) { this.p = p; this.q = q; value = p.price * q; } // -------------------------------------------- // Examples & Tests static OrderLine ol1 = new OrderLine(Product.p1,10); static OrderLine ol2 = new OrderLine(Product.p2,5); static OrderLine ol3 = new OrderLine(Product.p3,1); public static void main(String argv) { } } // ----------------------------------------------------------------------------- // representing a product class Product { String name; String description; int price; // -------------------------------------------- Product(String name, String description, int price) { this.name = name; this.description = description; this.price = price; } // -------------------------------------------- // Examples static Product p1 = new Product("salt","oh well",1); static Product p2 = new Product("pepper","so so",2); static Product p3 = new Product("jalapeno","yeap!",10); } // ----------------------------------------------------------------------------- // a minimal test infrastructure class Tester { static int faults = 0; static void check(String s, int i1, int i2) { check(s, new Integer(i1), new Integer(i2), i1==i2); } static void check(String s, Object o1, Object o2) { check(s, o1, o2, o1==o2); } static void check(String s, Object o1, Object o2, boolean t) { if (!t) { faults += 1; System.out.println("*** test failed: " + s + " got " + o1 + " expected " + o2 + " *** "); } } public static void main(String argv[]) { // calling all test methods in all classes } }