我想调用另一个类的构造函数和方法
问题描述:
我完全失去了。我必须创建一个公共分类帐,其当前的UTXOPool(未使用的事务输出的集合)是utcodeOrbject。这应该使用UTXOPool(UTXOPool uPool)构造函数复制utxoPool。我的代码粘贴下面..我想调用另一个类的构造函数和方法
public class TxHandler {
/**
* Creates a public ledger whose current UTXOPool (collection of unspent transaction outputs) is
* {@code utxoPool}. This should make a copy of utxoPool by using the UTXOPool(UTXOPool uPool)
* constructor.
*/
public TxHandler(UTXOPool utxoPool) {
// IMPLEMENT THIS
this.
}
/**
* @return true if:
* (1) all outputs claimed by {@code tx} are in the current UTXO pool,
* (2) the signatures on each input of {@code tx} are valid,
* (3) no UTXO is claimed multiple times by {@code tx},
* (4) all of {@code tx}s output values are non-negative, and
* (5) the sum of {@code tx}s input values is greater than or equal to the sum of its output
* values; and false otherwise.
*/
public boolean isValidTx(Transaction tx) {
// IMPLEMENT THIS
}
/**
* Handles each epoch by receiving an unordered array of proposed transactions, checking each
* transaction for correctness, returning a mutually valid array of accepted transactions, and
* updating the current UTXO pool as appropriate.
*/
public Transaction[] handleTxs(Transaction[] possibleTxs) {
// IMPLEMENT THIS
}
}
答
如果其他类放置在其他包,你需要确保两个你最初的类,并且要调用的方法是公共,然后在另一个类中需要导入最初的一个:
import your.original.package.TxHandler;
然后调用它的方法。
答
from the instruction - “这应该使用UTXOPool(UTXOPool uPool)构造函数复制utxoPool。”
所以你的建筑工应该是这样的
public TxHandler(UTXOPool utxoPool) {
// IMPLEMENT THIS
this.utxoPool = new UTXOPool(utxoPool)
}
那你试试?你得到什么异常?在编译时或运行时期间是否出现错误?您是否在Google上找到了该例外的解决方案? –
您可以复制代码[从其GitHub存储库](https://github.com/terryyannan/ScroogeCoin/blob/master/TxHandler.java)... –