Market
package market;
public class Market {
private String marname;
private Product[] productarr;
public Product[] getProductarr() {
return productarr;
}
public String getMarname() {
return marname;
}
public void setMarname(String marname) {
this.marname = marname;
}
public void setProductarr(Product[] productarr) {
this.productarr = productarr;
}
Product sell(String name){
for (int i = 0; i < productarr.length; i++) {
if (productarr.getProname() == name){
return productarr;
}
}
return null;
}
}
Person
package market;
public class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
Product shopping(Market market,String name){
return market.sell(name);
}
}
Product
package market;
public class Product {
private String proname;
public void setProname(String proname) {
this.proname = proname;
}
public String getProname() {
return proname;
}
}
Shopping
package market;
public class Shopping {
public static void main(String[] args) {
Product p1 = new Product();
Product p2 = new Product();
Product p3 = new Product();
Product p4 = new Product();
Product p5 = new Product();
// 创建商品类
p1.setProname("1");
p2.setProname("2");
p3.setProname("3");
p4.setProname("4");
p5.setProname("5");
// 给商品类赋名
Market m = new Market();
m.setMarname("k商店");
m.setProductarr (new new Product [] {p1, P2, p3, P4, P5});
// create a shop class, assigned a name to add items
the Person = new new the p-the Person ();
p.setName ( "alex");
Product = p.shopping Result (m, "20 is");
IF (! Result = null) {
System.out.println (p.getName () + "in the" + m.getMarname () + "buy" + result. getProname ());
} the else {
System.out.println (p.getName () + "in the" + m.getMarname () + "wasted journey");
}
}
}
More technical information may be concerned about: itheimaGZ get