Time 如何利用Joda的资金和时间实施交租制度

Time 如何利用Joda的资金和时间实施交租制度,time,jodatime,payment,currency,period,Time,Jodatime,Payment,Currency,Period,} 从接口复制的说明:可驻车 计算这两次之间停车场的费用。 指定人:界面中的computeCharge Parkable 参数:自-车辆进入时。 至-车辆释放的时间。 返回:这里停车的费用 例如,我们每小时收费8美元 @Override public org.joda.money.Money computeCharge(org.joda.time.DateTime from, org.joda.time.DateTime

}

从接口复制的说明:可驻车

计算这两次之间停车场的费用。 指定人:界面中的computeCharge Parkable 参数:自-车辆进入时。 至-车辆释放的时间。 返回:这里停车的费用

例如,我们每小时收费8美元

@Override
public org.joda.money.Money computeCharge(org.joda.time.DateTime from,
                                      org.joda.time.DateTime to){

第二个编码是我的计算器面板。因此,接口实例pk实现了computeCharge方法。然后,System.out.println(…“costs”+pk.computeCharge(from,to))。请帮帮我。

我写了这样的东西

private void updateCharge() {
    jtc.setText(jcb.getSelectedItem() + " for " + jtf.getText());

    DateTime from = new DateTime(arriveTime.getDate());
    DateTime to = new DateTime(departTime.getDate());
    Period p = new Period(from, to);

    Parkable pk = (Parkable) jcb.getSelectedItem();
    pk.computeCharge(from, to);
    jtc.setText(pk.computeCharge(from, to).toString());
    System.out.println(jcb.getSelectedItem() + " for " + jtf.getText()
            + " costs " + pk.computeCharge(from, to));
}
您可以根据您的案例修改此选项

输出为

public static void main(String[] args) {
    DateTime to = new DateTime().minusHours(3).minusSeconds(30);
    DateTime from = new DateTime();
    System.out.println("Total Amount is = " + computeCharge(from, to));
}

public static Money computeCharge(DateTime from, DateTime to) {
    int hourlyAmount = 8;
    Money result = Money.of(CurrencyUnit.USD, hourlyAmount);
    Minutes minutes = Minutes.minutesBetween(to, from);
    return result.multipliedBy(minutes.getMinutes() / 60);
}

你试过我的答案了吗?
Total Amount is = USD 24.00