interface Lookup{ Object find(String name);
}
class LookupProduct implements Lookup{
private String[] productNames={"Cloth","Bike","Car"};
private Object[] productPrices={new Integer(100),new Integer(200),new
Integer(300)};
LookupProduct(){ }
public Object find(String name){
for(int i=0;i <productNames.length;i++)
if(productNames[i].equals(name))
return productPrices[i];
return null;
}
}
public class LookupDemo{
public void processValues(String[] name,Lookup table){
for(int i=0;i<name.length;i++){
Object value = table.find(name[i]);
if(value != null)
System.out.println("Product "+name[i]+" Price="+ value);
}
}
public static void main(String[] args){
String[] productArray = {"bike","Car","Paper"};
LookupProduct lp = new LookupProduct();
new LookupDemo().processValues(productArray,lp);
}