Java Debug Notes Chapter One (reference delivery) (one-to-many)

Source: Internet
Author: User

Class Item
{private int iid;
private String name;
private String Note;
Private subitem subitem[];
Private Product product[];
Public Item (int iid,string name,string Note) {
THIS.IID=IID;
This.name=name;
This.note=note;
}
Public Item () {}
public void SetName (String name) {
This.name=name;
}
Public String GetName () {
return this.name;
}
public void setiid (int iid) {
THIS.IID=IID;
}
public int getiid () {
return this.iid;
}
public void Setnote (String note) {
This.note=note;
}
Public String Getnote () {
return this.note;
}
public void Setsubitem (subitem subitem[])
{
This.subitem=subitem;
}
Public Subitem[]getsubitem ()
{
return this.subitem;
}
public void Setproduct (Product product[])
{
This.product=product;
}
Public Product[]getproduct ()
{
return this.product;
}
Public String GetInfo () {
Return "parent column" +this.iid+this.name+this.note;
}
}
Class Subitem
{private int sid;
private String name;
private String Note;
Private item Item;
Private Product product[];
Public subitem (int sid, String name, string note) {
This.sid=sid;
This.name=name;
This.note=note;
}
Public subitem () {}
public void SetItem (item item)
{
This.item=item;
}
Public Item GetItem ()
{
return this.item;
}
public void Setproduct (Product product[])
{
This.product=product;
}
Public Product[]getproduct ()
{
return this.product;
}
public void SetName (String name) {
This.name=name;
}
Public String GetName () {
return this.name;
}
public void Setsid (int sid) {
This.sid=sid;
}
public int GetSID () {
return this.sid;
}
public void Setnote (String note) {
This.note=note;
}
Public String Getnote () {
return this.note;
}
Public String GetInfo () {
Return "sub-column" +this.sid+this.name+this.note;
}
}
Class Product
{
private int pid;
private String name;
private double price;
Private item Item;
Private subitem subitem[];
public Product (int pid, String name, double price) {
This.pid=pid;
This.name=name;
This.price=price;
}
Public Product () {}
public void Setsubitem (subitem subitem[])
{
This.subitem=subitem;
}
Public subitem[] Getsubitem ()
{
return this.subitem;
}
public void SetItem (item item)
{
This.item=item;
}
Public Item GetItem ()
{
return this.item;
}
public void setpid (int pid)
{
This.pid=pid;
}
public int Getpid ()
{
return this.pid;
}
public void SetName (String name)
{
This.name=name;
}
Public String SetName ()
{
return this.name;
}
public void Setprice (double price) {
This.price=price;
}
Public double GetPrice () {
return this.price;
}
Public String GetInfo () {
Return "commodity" +this.pid+this.name+this.price;
}
}
public class Pctestse
{
public static void Main (String args[])
{
Item Item=new Item (1, "kitchen Utensils", "1");
Subitem Suba=new Subitem (1001, "Cutter", "2");
Subitem Subb=new Subitem (1001, "Cutter", "2");
Subitem Subc=new Subitem (1001, "Cutter", "2");
Product Proa=new Product (1002, "knife", 20);
Product Prob=new product (1003, "knife", 20);
Suba.setitem (item);
Suba.setitem (item);
Suba.setitem (item);
Item.setsubitem (New SUBITEM[]{SUBA,SUBB,SUBC});
Proa.setsubitem (Suba);
Proa.setitem (item);
Prob.setsubitem (Subb);
Prob.setitem (item);
Suba.setproduct (ProA);
Subb.setproduct (prob);
Find all of its subtypes by one type
System.out.println (Item.getinfo ());
Find all the goods that it corresponds to by one type, and the sub-type of each product
for (int x=0,x<item.getsubitem (). length,x++)
//{
System.out.println (Item.getproduct () [X].getinfo ());
System.out.println (Item.getsubitem () [X].getinfo ());
Find all of the corresponding products by one sub-type
for (int x=0,x<item.getsubitem (). length,x++)
//{
System.out.println (Item.getsubitem () [X].getinfo ());
//}
}
}

Error:

Class Item
{private int iid;
private String name;
private String Note;
Private subitem subitems[]; Array plus plural
Private Product products[];
Public Item (int iid,string name,string Note) {
THIS.IID=IID;
This.name=name;
This.note=note;
}
Public Item () {}
public void SetName (String name) {
This.name=name;
}
Public String GetName () {
return this.name;
}
public void setiid (int iid) {
THIS.IID=IID;
}
public int getiid () {
return this.iid;
}
public void Setnote (String note) {
This.note=note;
}
Public String Getnote () {
return this.note;
}
public void Setsubitems (subitem subitems[])
{
This.subitems=subitems;
}
Public Subitem[]getsubitems ()
{
return this.subitems;
}
public void Setproducts (Product products[])
{
this.products=products;
}
Public Product[]getproducts ()
{
return this.products;
}
Public String GetInfo () {
Return "parent column" +this.iid+this.name+this.note;
}
}
Class Subitem
{private int sid;
private String name;
private String Note;
Private item Item;
Private Product products[];
Public subitem (int sid, String name, string note) {
This.sid=sid;
This.name=name;
This.note=note;
}
Public subitem () {}
public void SetItem (item item)
{
This.item=item;
}
Public Item GetItem ()
{
return this.item;
}
public void Setproducts (Product products[])
{
this.products=products;
}
Public Product[]getproducts ()
{
return this.products;
}
public void SetName (String name) {
This.name=name;
}
Public String GetName () {
return this.name;
}
public void Setsid (int sid) {
This.sid=sid;
}
public int GetSID () {
return this.sid;
}
public void Setnote (String note) {
This.note=note;
}
Public String Getnote () {
return this.note;
}
Public String GetInfo () {
Return "sub-column" +this.sid+this.name+this.note;
}
}
Class Product
{
private int pid;
private String name;
private double price;
Private item Item;
Private subitem subitem; is not a plural, a commodity belongs to a sub-type
public Product (int pid, String name, double price) {
This.pid=pid;
This.name=name;
This.price=price;
}
Public Product () {}
public void Setsubitem (subitem subitem)
{
This.subitem=subitem;
}
Public subitem Getsubitem ()
{
return this.subitem;
}
public void SetItem (item item)
{
This.item=item;
}
Public Item GetItem ()
{
return this.item;
}
public void setpid (int pid)
{
This.pid=pid;
}
public int Getpid ()
{
return this.pid;
}
public void SetName (String name)
{
This.name=name;
}
Public String SetName ()
{
return this.name;
}
public void Setprice (double price) {
This.price=price;
}
Public double GetPrice () {
return this.price;
}
Public String GetInfo () {
Return "commodity" +this.pid+this.name+this.price;
}
}
public class Pctestse
{
public static void Main (String args[])
{
Item Item=new Item (1, "kitchen Utensils", "1");
Subitem Suba=new Subitem (1001, "Cutter", "2");
Subitem Subb=new Subitem (1001, "Cutter", "2");
Subitem Subc=new Subitem (1001, "Cutter", "2");
Product Proa=new Product (1002, "knife", 20);
Product Prob=new product (1003, "knife", 20);
Suba.setitem (item);
Suba.setitem (item);
Suba.setitem (item);
Item.setsubitems (New SUBITEM[]{SUBA,SUBB,SUBC});
Proa.setsubitem (Suba);
Proa.setitem (item);
Prob.setsubitem (Subb);
Prob.setitem (item);
Suba.setproducts (New Product[]{proa,prob});
Subb.setproducts (New Product[]{proa,prob});
Find all of its subtypes by one type
System.out.println (Item.getinfo ());

for (int x=0;x<item.getsubitems (). length;x++)
{

System.out.println (Item.getsubitems () [X].getinfo ());
}
Find all the goods that it corresponds to by one type, and the sub-type of each product
System.out.println (Item.getinfo ());

for (int x=0;x<item.getproducts (). length;x++)
{
System.out.println (Item.getproducts () [X].getinfo ());
System.out.println (Item.getproducts () [X].getsubitem (). GetInfo ());
}

Find all of the corresponding products by one sub-type
System.out.println (Subb.getinfo ());
for (int x=0;x<subb.getproducts (). length;x++)
{
System.out.println (Subb.getproducts () [X].getinfo ());

}
}
}

Java Debug Notes Chapter One (reference delivery) (one-to-many)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.