class Member {
private String mid;
private String name;
private Product products[];
public Member(String mid,String name){
this.mid = mid;
this.name = name;
}
public void setProducts(Product products[]){
this.products = products;
}
public Product[] getProducts(){
return this.products;
}
public String getInfo(){
return "【用户信息】 mid=" + this.mid + ",name=" + this.name;
}
}
class Product {
private long pid;
private String title;
private double price;
private Member members[];
public Product(long pid,String title,double price){
this.pid = pid;
this.title = title;
this.price = price;
}
public void setMembers(Member members[]){
this.members = members;
}
public Member[] getMembers(){
return this.members;
}
public String getInfo(){
return "【商品信息】pid=" + this.pid + ",title=" + this.title + ",price=" + this.price;
}
}
public class HelloWorld {
public static void main(String[] args){
// 第一步,根据构造设置对象数据
Member memA = new Member("mldn","张三");
Member memB = new Member("mldnjava","李四");
Product proA = new Product(1L,"Java开发图书",79.8);
Product proB = new Product(2L,"非常大的B的耳机",2309.9);
Product proC = new Product(3L,"小米手机",3000.9);
memA.setProducts(new Product[] {proA,proB,proC});
memB.setProducts(new Product[] {proA});
proA.setMembers(new Member[] {memA,memB});
proB.setMembers(new Member[] {memA});
proC.setMembers(new Member[] {memA});
// 第二步:根据要求获取数据
System.out.println("-----------根据用户查看浏览商品信息-----------------------");
System.out.println(memA.getInfo());
for(int x = 0;x < memA.getProducts().length;x++){
System.out.println("\t|-" + memA.getProducts()[x].getInfo());
}
System.out.println("-----------根据商品找到被浏览的记录-----------------------");
System.out.println(proA.getInfo());
for(int x = 0;x < proA.getMembers().length;x++){
System.out.println("\t|-" + proA.getMembers()[x].getInfo());
}
}
}
标签:Product,转换,String,映射,memA,Member,6.6,new,public
From: https://www.cnblogs.com/pansidong/p/17459908.html