![](/img/trans.png)
[英]What should be the name of the prev_node argument passed into the method given below?
[英]Should I create a method or variable for the table given below
I have an assignment which says that I need to create an queue class with instruction messages on it.
and instruction message is formed of following properties
-----------
>InstructionType integer
> ProductCode integer
> Quantity integer
> UOM byte
--------------------------------
Can I declare all the above given properties as variables and then pass it as a parameter in a function created for instruction message and place it in the instruction queue class. Can anyone give me a sample code for proceeding with this..and let me know if I think right or any other methodologies. Can be done? please help.
任何人都可以建議,如果是正確的。我可以這樣使用:
公共類指令隊列{LinkedList queue = new LinkedList()/ *如何從隊列類中添加,刪除和刪除指令消息* /} insturctionmessage是一個類
public class Instructionmessage
{
public int Instructiontype;
public Integer Productcode;
public Integer quantity;
public byte[] UOM = new byte[256];
public Integer Timestamp;
/*method to set and get the instruction type for the messages*/
public int getInstructiontype()
{
return Instructiontype;
}
public void setInstructiontype(int newInstructtype)
{
Instructiontype = newInstructtype;
}
/*method to set and get the product code for the messages*/
public int getProductcode()
{
return Productcode;
}
public void setProductCode(int newproductcode)
{
Productcode = newproductcode;
}
/*method to set and get the quantity for the messages*/
public int getquantity()
{
return quantity;
}
public void setquantity(int newquantity)
{
quantity = newquantity;
}
/*method to set and get the Timestamp for the messages*/
public int getTimestamp ()
{
return Timestamp;
}
public void setTimestamp(int newTimestamp)
{
Timestamp = newTimestamp;
}
/*method to set and get the UOM for the messages*/
public byte[] getUOM()
{
return UOM;
}
public void setUOM(byte[] newUOM)
{
UOM = newUOM;
}
}
由於指令消息包含4個字段,因此您可以創建一個Instruction類來封裝它們。 然后,對於隊列,您可以使用列表,並在列表中填充“說明”。 例如,實例化
LinkedList<Instruction> queue = new LinkedList<Instruction>();
然后,您可以使用queue.getFirst()和queue.addLast(...)來操縱隊列的內容。
用所有變量創建一個POJO Java類。 為所有變量創建getter和setter。 這將幫助您使用這些方法設置和獲取數據。
現在在您的主類中創建一個Queue對象,並使用add(Object)方法將其添加到隊列中。
Queue<String> sampleQueue = new LinkedList<String>();
sampleQueue.add("Joseph");
sampleQueue.add("Madhonna");
注意:隊列是一個接口,因此無法實例化該對象。
使用此方法時,可能會引發異常。 請參閱此鏈接以獲取更多詳細信息http://docs.oracle.com/javase/6/docs/api/java/util/Queue.html#add(E)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.