interface Lookup
{
Object find (String name);
}
class LookupProduct implements Lookup
{
private String[] productNames={"cloth","bike","car"};
private Object[] productPrices={new Integer(100),new Integer(2000),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 processValus(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);
else
System.out.println("Product "+name[i]+" Not Found");
}
}
public static void main(String args[])
{
String productArry[]={"bike","car","paper"};
LookupProduct ip=new LookupProduct();
new LookupDemo().processValus(productArry,ip);
}
}
{
Object find (String name);
}
class LookupProduct implements Lookup
{
private String[] productNames={"cloth","bike","car"};
private Object[] productPrices={new Integer(100),new Integer(2000),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 processValus(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);
else
System.out.println("Product "+name[i]+" Not Found");
}
}
public static void main(String args[])
{
String productArry[]={"bike","car","paper"};
LookupProduct ip=new LookupProduct();
new LookupDemo().processValus(productArry,ip);
}
}
解决方案 »
- JBoss AS 与tomcat的区别
- 如何查询JS中是否存在指定的字符,在线等
- 请教一个抽象工厂依赖关系的问题
- 有关request.getParameterValues的问题
- 用Hibernate的时候,pojo 中能不能定义Map类型的成员变量,为什么?
- java.io.CharConversionException: isHexDigit
- 一个Spring的中文乱码的问题?
- 请教LOG4J的问题。如何根据不同的优先级别把日志写到不同的文件中?
- DUKE在线银行问题。。
- 我现在写一个java与松下plc通讯,不知道怎么向plc发送指令和接受指令
- j2ee项目问题交流
- 为什么他们的输出结果是before==strArry[0]=Hello strarry[1]=Word after==strArry[0]=Word str
processValus有两个参数String[] name,Lookup table
productArry[]是个String数组,ip是LookupProduct类的对象,而LookupProduct implements Lookup,所以以上两个参数可供processValus方法使用。PS:数组声明用String[] productArry={"bike","car","paper"}更好。