首页 > 解决方案 > 排队存储有关交易的成本

问题描述

我打算将这些值中的 6 个存储在一个队列中,当它达到限制 6 时,它将执行 FIFO 测量。

我的问题是如何显示字符串数据类型的详细信息,例如交易名称、涉及的公司等。我显然不能在队列中这样做;只保存一种数据类型。

//Both are declared in a class
private float Amount; 
Queue <Float> Transactions = new LinkedList <Float>();

//In a method via a parameter to add to a queue
Transactions.offer(Cost);

新示例:

public void New_Transaction(String Transaction, float Cost, String 
Date_Time) {                            
    Transaction_Type = Transaction;
    Transactions.offer(Cost);
    Date_an_Time = Date_Time;        
}

标签: javaqueue

解决方案


您使用事务名​​称、所涉及的公司和其他名称创建一个对象作为字段,然后将该对象用作队列事务的数据类型。希望这可以帮助。


推荐阅读