Professional Documents
Culture Documents
ArrayList;
public class Selection2 {
public static void main(String args[]) {
Product pl = new Product("beef", 5);
Product p2 = new Product("milk", 2);
Product p3 = new Product("ziti", 8);
Product p4 = new Product("cheese", 3);
MyContext ctx = new MyContext();
ctx.addProduct(p1);
ctx.addProduct(p2);
ctx.addProduct(p3);
ctx.addProduct(p4);
ctx.setWorker(new NameWorker());
ctx.showProductsInPriceRange (2, 5);
ctx.setWorker(new PriceWorker());
ctx.showProductsInPriceRange (3, 8);
}
}
class Product {
private String name;
private int price;
public Product(String name, int price) {
this.name = name;
this.price = price;
}
class MyContext {