【问题标题】:How to implement pay rent system with Joda money and time如何用 Joda 的金钱和时间实施支付租金制度
【发布时间】:2015-06-21 06:20:52
【问题描述】:
@Override
public org.joda.money.Money computeCharge(org.joda.time.DateTime from,
                                      org.joda.time.DateTime to){

}

从界面复制的描述:Parkable

计算这些时间之间在该地段停车的费用。 指定者:Parkable接口中的computeCharge 参数:from - 车辆进入的时间。 to - 释放车辆的时间。 返回:这里停车的费用。

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

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));
}

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

【问题讨论】:

  • 你试过我的答案了吗?

标签: time jodatime payment currency period


【解决方案1】:

我写了这样的东西;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 2015-10-11
    • 1970-01-01
    • 2020-07-31
    • 2013-11-12
    • 2016-10-22
    • 1970-01-01
    相关资源
    最近更新 更多