计算气体损失量并将汽车的当前气体容量设置为新值。 我忘了将这部分添加到问题中。气体量不超过顶部气体容量。我想知道这是对的吗?如何编写accessor和mutator?
private final int GAS_CAP = 30
public int getGasCapacity(int gasCapacity)
{
if(currentGas <= GAS_CAP)
{
gasCapacity = GAS_CAP - currentGas;
}
else gasCapacity = currentGas;
return gasCapacity;
}
您正在要求用户使用此方法来提供气体容量以计算气体容量。你为什么要提供任何东西? – 2014-10-18 07:53:09